Commit b00d7165 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Manual.rst: Add documentation for FormElement.type=sendmail - attachments

SendMail.php: renamed file and class from 'sendmail' to 'sendMail'. Remove obsolete function buildHeader().
AutoCron.php: Update use of class sendMail().
FormAction.php: rename function sendmail(0 to doSendMail().
Report.php: remove unnecessary code. Move sendmailConvertToken() to class sendMail / parseStringToArray().
parent 04511e82
......@@ -3386,7 +3386,7 @@ Type: sendmail
* *sendMailFrom* - Sender of the email. Optional: 'realname <john@doe.com>'. **Mandatory**.
* *sendMailSubject* - Subject of the email.
* *sendMailReplyTo* - Reply this email address. Optional: 'realname <john@doe.com>'.
* *sendMailAttachment* - List of files to attach to the mail. Multiple files separated by comma.
* *sendMailAttachment* - List of 'sources' to attach to the mail as files. Check `attachment`_ for options.
* *sendMailHeader* - Specify custom header.
* *sendMailFlagAutoSubmit* - **on|off** - If 'on' (default), the mail contains the header
'Auto-Submitted: auto-send' - this suppress a) OoO replies, b) forwarding of emails.
......@@ -3396,10 +3396,14 @@ Type: sendmail
* *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}}`
* To use the `id` of a new created or already existing primary record, use the STORE_RECORD. E.g. `{{id:R}}`.
* For debugging, please check `REDIRECT_ALL_MAIL_TO`_.
Example to attach one file and concatenate PDF files to one, whoose source are web pages: ::
sendMailAttachmemt = F:fileadmin/file1.pdf|d:readme.pdf|C|u:http://www.example.com|U:?id=export&r=123&_sip=1|d:personal.pdf
Type: paste
'''''''''''
......@@ -5327,38 +5331,53 @@ Additional the CEO as well as backup will receive the mail via CC and BCC.
For debugging, please check `REDIRECT_ALL_MAIL_TO`_.
.. _attachment:
Attachment
''''''''''
The following types are provided:
The following options are provided to attach files to an email:
* Attach a single file: `F:<filename>`. Any filetype is possible.
* Convert a Webpage to a PDF and attach that one: `u:http://www.john-doe.com/a?param1=x&...`.
* Convert a T3 page to a PDF and attach that one: `U:<T3 alias>&param1=x&...`.
+-------+------------------------------------------------------+--------------------------------------------------------+
| Token | Example | Comment |
+=======+======================================================+========================================================+
| F | F:fileadmin/file3.pdf | Single file to attach |
+-------+------------------------------------------------------+--------------------------------------------------------+
| u | u:www.example.com/index.html?key=value&... | A URL, will be converted to a PDF and than attached. |
+-------+------------------------------------------------------+--------------------------------------------------------+
| U | U:?id=export&r=123&_sip=1 | A SIP protected local T3 page. |
| | | Will be converted to a PDF and than attached. |
+-------+------------------------------------------------------+--------------------------------------------------------+
| d | d:myfile.pdf | Name of the attachment in the email. |
+-------+------------------------------------------------------+--------------------------------------------------------+
| C | C|u:http://www.example.com|F:file1.pdf|C|F:file2.pdf | Concatenate all named sources to one PDF file. The |
| | | souces has to be PDF files or a web page, which will be|
| | | converted to a PDF first. |
+-------+------------------------------------------------------+--------------------------------------------------------+
* Optional any combination (incl. repeating) are possible. Any now source will be added as a single attachment.
Any combination (incl. repeating them) are possible. Any source will be added as a single attachment.
* Optional any number of sources can be concatenated to a single PDF file: 'C|F:<file1>|F:<file2>|U:export&a=123'.
Only PDF files can be concatenated.
Optional any number of sources can be concatenated to a single PDF file: 'C|F:<file1>|F:<file2>|U:export&a=123'.
* User definable filename for the attachment: `d:<filename>`.
Examples in Report::
Examples::
# One file attached
# One file attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|F:fileadmin/summary.pdf" AS _sendmail
# Two files attached
# Two files attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|F:fileadmin/summary.pdf|F:fileadmin/detail.pdf" AS _sendmail
# Two files and a webpage (converted to PDF) are attached
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|F:fileadmin/summary.pdf|F:fileadmin/detail.pdf|U:export&r=123|d:person.pdf" AS _sendmail
# Two files and a webpage (converted to PDF) are attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|F:fileadmin/summary.pdf|F:fileadmin/detail.pdf|U:?id=export&r=123|d:person.pdf" AS _sendmail
# Two webpages (converted to PDF) are attached
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|U:export&r=123|d:person123.pdf|U:export&r=234|d:person234.pdf" AS _sendmail
# Two webpages (converted to PDF) are attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|U:?id=export&r=123|d:person123.pdf|U:?id=export&r=234|d:person234.pdf" AS _sendmail
# One file and two webpages (converted to PDF) are *concatenated* to one PDF and attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|C|F:fileadmin/summary.pdf|U:export&r=123|U:export&r=234|d:complete.pdf" AS _sendmail
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|C|F:fileadmin/summary.pdf|U:?id=export&r=123|U:?id=export&r=234|d:complete.pdf" AS _sendmail
# One T3 webpage, protected by a SIP, are attached.
10.sql = SELECT "t:john.doe@example.com|F:company@example.com|s:Latest News|b:The new version is now available.|U:?id=export&r=123&_sip=1|d:person123.pdf" AS _sendmail
.. _column_img:
......@@ -5480,7 +5499,7 @@ Most of the other Link-Class attributes can be used to customize the link.
SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _pdf, "d:complete.zip|t:Download ZIP|F:fileadmin/test1.pdf|F:fileadmin/test2.pdf" as _zip
SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test.pdf|U:id=export&r=1|u:www.w3c.org" AS _pdf
SELECT "d:complete.pdf|t:Download PDF|F:fileadmin/test.pdf|U:id=export&r=1|u:www.example.com" AS _pdf
.. _column_ppdf:
......
......@@ -15,7 +15,7 @@ require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/database/Database.php');
require_once(__DIR__ . '/../qfq/exceptions/ShellException.php');
require_once(__DIR__ . '/../qfq/Evaluate.php');
require_once(__DIR__ . '/../qfq/report/Sendmail.php');
require_once(__DIR__ . '/../qfq/report/SendMail.php');
class AutoCron {
......@@ -164,7 +164,9 @@ class AutoCron {
$mailArr = $this->evaluate->parse($job[AUTOCRON_SQL1]);
$mailsSent = 0;
$sendMail = new SendMail();
$mailCount = 0;
foreach ($mailArr as $mailEntry) {
$this->store->setStore($mailEntry, STORE_PARENT_RECORD, true);
......@@ -191,11 +193,11 @@ class AutoCron {
$mail[SENDMAIL_IDX_SRC] = "AutoCron: Cron.id=" . $job[COLUMN_ID];
// Mail: send
new Sendmail($mail);
$mailsSent++;
$sendMail->process($mail);
$mailCount++;
}
$job[AUTOCRON_LAST_STATUS] = "OK: $mailsSent mails sent";
$job[AUTOCRON_LAST_STATUS] = "OK: $mailCount mails sent";
return $job;
}
......
......@@ -875,6 +875,7 @@ 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_ATTACHMENT = 'sendMailAttachment'; // x_id: used to classify mail log entries in 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
......@@ -1063,7 +1064,7 @@ const COLUMN_PATH_FILE_NAME = 'pathFileName';
const EXISTING_PATH_FILE_NAME = '_existingPathFileName';
//SENDMAIL
const SENDMAIL_IDX_ARRAY = -1;
const SENDMAIL_IDX_ARRAY = -1; // Placeholder to indicate special handling
const SENDMAIL_IDX_RECEIVER = 0;
const SENDMAIL_IDX_SENDER = 1;
const SENDMAIL_IDX_SUBJECT = 2;
......
......@@ -12,7 +12,7 @@ require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../database/Database.php');
require_once(__DIR__ . '/../store/Store.php');
require_once(__DIR__ . '/../Evaluate.php');
require_once(__DIR__ . '/../report/Sendmail.php');
require_once(__DIR__ . '/../report/SendMail.php');
require_once(__DIR__ . '/../helper/HelperFormElement.php');
require_once(__DIR__ . '/../exceptions/UserFormException.php');
......@@ -164,7 +164,7 @@ class FormAction {
}
if ($fe[FE_TYPE] === FE_TYPE_SENDMAIL) {
$this->sendMail($fe);
$this->doSendMail($fe);
//no further processing of current element necessary.
continue;
}
......@@ -239,24 +239,30 @@ class FormAction {
/**
* @param array $feSpecAction
*/
private function sendMail(array $feSpecAction) {
$mail[SENDMAIL_IDX_RECEIVER] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_TO]);
$mail[SENDMAIL_IDX_SENDER] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_FROM]);
$mail[SENDMAIL_IDX_SUBJECT] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_SUBJECT]);
$mail[SENDMAIL_IDX_BODY] = $this->evaluate->parse($feSpecAction[FE_VALUE]);
$mail[SENDMAIL_IDX_REPLY_TO] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_REPLY_TO]);
$mail[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_FLAG_AUTO_SUBMIT]) === 'off' ? 'off' : 'on';
$mail[SENDMAIL_IDX_GR_ID] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_GR_ID]);
$mail[SENDMAIL_IDX_X_ID] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID]);
$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]);
private function doSendMail(array $feSpecAction) {
$args = array();
$args[] = SENDMAIL_TOKEN_RECEIVER . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_TO]);
$args[] = SENDMAIL_TOKEN_SENDER . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_FROM]);
$args[] = SENDMAIL_TOKEN_SUBJECT . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_SUBJECT]);
$args[] = SENDMAIL_TOKEN_BODY . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_VALUE]);
$args[] = SENDMAIL_TOKEN_REPLY_TO . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_REPLY_TO]);
$autoSubmit = ($this->evaluate->parse($feSpecAction[FE_SENDMAIL_FLAG_AUTO_SUBMIT]) === 'off') ? 'off' : 'on';
$args[] = SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT . PARAM_TOKEN_DELIMITER . $autoSubmit;
$args[] = SENDMAIL_TOKEN_GR_ID . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_GR_ID]);
$args[] = SENDMAIL_TOKEN_X_ID . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_X_ID]);
$args[] = SENDMAIL_TOKEN_RECEIVER_CC . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_CC]);
$args[] = SENDMAIL_TOKEN_RECEIVER_BCC . PARAM_TOKEN_DELIMITER . $this->evaluate->parse($feSpecAction[FE_SENDMAIL_BCC]);
$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[] = $this->evaluate->parse($feSpecAction[FE_SENDMAIL_ATTACHMENT]);
// Mail: send
new Sendmail($mail);
$sendMail = new SendMail();
$mailConfig = $sendMail->parseStringToArray(implode(PARAM_DELIMITER, $args));
$sendMail->process($mailConfig);
}
/**
......@@ -298,7 +304,7 @@ class FormAction {
$msg = $this->evaluate->parse($fe[FE_MESSAGE_FAIL]); // Replace possible dynamic parts
// Throw user defineable error message
// Throw user error message
throw new UserFormException($msg, ERROR_REPORT_FAILED_ACTION);
}
......
......@@ -16,7 +16,7 @@ require_once(__DIR__ . '/Variables.php');
require_once(__DIR__ . '/Error.php');
require_once(__DIR__ . '/../database/Database.php');
require_once(__DIR__ . '/Link.php');
require_once(__DIR__ . '/Sendmail.php');
require_once(__DIR__ . '/SendMail.php');
require_once(__DIR__ . '/../exceptions/UserReportExtension.php');
require_once(__DIR__ . '/../Evaluate.php');
require_once(__DIR__ . '/../helper/KeyValueStringParser.php');
......@@ -767,54 +767,18 @@ class Report {
break;
case "sendmail":
// '<receiver1>,<receiver2>,...|<sender>|<subject>|<body>|<reply-to>|<flag autosubmit: on /off>'
// $mailarr = explode("|", $columnValue);
$mailConfig = $this->sendmailConvertToken($columnValue);
$sendMail = new SendMail();
$mailConfig = $sendMail->parseStringToArray($columnValue);
if (count($mailConfig) < 4) {
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL, null, __FILE__, __LINE__, $this->fr_error);
}
// if (!isset($mailarr[SENDMAIL_IDX_REPLY_TO])) {
// $mailarr[SENDMAIL_IDX_REPLY_TO] = '';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT])) {
// $mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = 'on';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_GR_ID])) {
// $mailarr[SENDMAIL_IDX_GR_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
// $mailarr[SENDMAIL_IDX_X_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_CC])) {
// $mailarr[SENDMAIL_IDX_RECEIVER_CC] = '';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_BCC])) {
// $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';
// }
$mailConfig[SENDMAIL_IDX_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
", T3 ttcontentId=" . $this->store->getVar('ttcontentUid', STORE_TYPO3) .
", Level=" . $full_level;
new Sendmail($mailConfig);
$sendMail->process($mailConfig);
break;
case "vertical":
......@@ -1266,107 +1230,4 @@ class Report {
return false;
}
/**
* Convert a token based sendmail string into a numerical index based array.
* Each attachment (single file or combined) 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
* @throws CodeException
* @throws UserReportException
*/
public 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_RECEIVER_CC => SENDMAIL_IDX_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_HEADER => SENDMAIL_IDX_HEADER,
SENDMAIL_TOKEN_CONCAT => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_DOWNLOAD_FILENAME => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_ATTACHMENT_FILE => SENDMAIL_IDX_ATTACHMENT,
SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED => SENDMAIL_IDX_ATTACHMENT,
SENDMAIL_TOKEN_ATTACHMENT_URL => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL => SENDMAIL_IDX_ARRAY,
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_SRC => SENDMAIL_IDX_SRC,
SENDMAIL_TOKEN_X_ID2 => SENDMAIL_IDX_X_ID2,
SENDMAIL_TOKEN_X_ID3 => SENDMAIL_IDX_X_ID3
];
// Token based string? No: just explode and all is fine. This is the deprecated fixed position setup
if (!isset($data[1]) || $data[1] != PARAM_TOKEN_DELIMITER) {
return explode(PARAM_DELIMITER, $data);
}
$segments = explode(PARAM_DELIMITER, $data);
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
$attachment = array();
$flagConcat = false;
$flagSource = false;
$flagFilename = false;
foreach ($segments AS $line) {
if (!isset($sendmailToken[$line[0]])) {
throw new UserReportException ("Unknown token in sendmail: " . $line, ERROR_UNKNOWN_TOKEN);
}
switch ($line[0]) {
case SENDMAIL_TOKEN_CONCAT:
$flagConcat = true;
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
}
break;
case SENDMAIL_TOKEN_ATTACHMENT_FILE:
case SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED:
case SENDMAIL_TOKEN_ATTACHMENT_URL:
case SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL:
if ($flagSource && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
$flagFilename = false;
}
$flagSource = true;
$attachment[] = $line;
break;
case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
if ($flagFilename && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
$flagSource = false;
}
$flagFilename = true;
$attachment[] = $line;
break;
default:
$idx = $sendmailToken[$line[0]];
if ($idx < 0 || $idx > count($sendmailToken)) {
throw new UserReportException('Token index in _sendmail invalid: ' . $idx, ERROR_INVALID_VALUE);
}
$arr[$idx] = substr($line, 2);
break;
}
}
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
}
return ($arr);
}
}
......@@ -11,7 +11,7 @@ require_once(__DIR__ . '/../helper/Sanitize.php');
require_once(__DIR__ . '/../helper/HelperFile.php');
class Sendmail {
class SendMail {
/**
* @var Store
......@@ -46,7 +46,16 @@ class Sendmail {
*
* @throws UserFormException
*/
public function __construct(array $mailConfig) {
public function __construct() {
$this->store = Store::getInstance('');
}
/**
*
*/
public function process(array $mailConfig) {
// If there is no 'Receiver': do not send a mail.
if (!isset($mailConfig[SENDMAIL_IDX_RECEIVER]) || $mailConfig[SENDMAIL_IDX_RECEIVER] === '') {
......@@ -197,36 +206,6 @@ class Sendmail {
return $attachmentsLine;
}
/**
* @param array $mailConfig
*
* @return string
*/
private function buildHeader(array $mailConfig) {
// "\r\n" needs to be enclosed in double ticks to correctly converted to 0x0d 0x0a,
$header = "From: " . $mailConfig[SENDMAIL_IDX_SENDER] . "\r\n";
if (isset($mailConfig[SENDMAIL_IDX_REPLY_TO]) && $mailConfig[SENDMAIL_IDX_REPLY_TO] != '') {
$header .= "Reply-To: " . $mailConfig[SENDMAIL_IDX_REPLY_TO] . "\r\n";
}
// By default 'on'
if (!isset($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === 'on') {
$header .= "Auto-Submitted: auto-send\r\n";
}
if (isset($mailConfig[SENDMAIL_IDX_RECEIVER_CC]) && $mailConfig[SENDMAIL_IDX_RECEIVER_CC] != '') {
$header .= "Cc: " . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . "\r\n";
}
if (isset($mailConfig[SENDMAIL_IDX_RECEIVER_BCC]) && $mailConfig[SENDMAIL_IDX_RECEIVER_BCC] != '') {
$header .= "Bcc: " . $mailConfig[SENDMAIL_IDX_RECEIVER_BCC] . "\r\n";
}
return $header;
}
/**
* Creates a new MailLog Record based on $mailArr / $header.
*
......@@ -354,4 +333,112 @@ class Sendmail {
return $files;
}
/**
* Convert a token based sendMail string into an array.
* - Each attachment (single file or mulitple 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
* @throws UserFormException
* @throws UserReportException
*/
public function parseStringToArray($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_RECEIVER_CC => SENDMAIL_IDX_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_HEADER => SENDMAIL_IDX_HEADER,
SENDMAIL_TOKEN_CONCAT => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_DOWNLOAD_FILENAME => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_ATTACHMENT_FILE => SENDMAIL_IDX_ATTACHMENT,
SENDMAIL_TOKEN_ATTACHMENT_URL => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL => SENDMAIL_IDX_ARRAY,
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_SRC => SENDMAIL_IDX_SRC,
SENDMAIL_TOKEN_X_ID2 => SENDMAIL_IDX_X_ID2,
SENDMAIL_TOKEN_X_ID3 => SENDMAIL_IDX_X_ID3
];
// Token based string? No: just explode and all is fine. This is the deprecated fixed position setup. Attachments are not supported.
if (!isset($data[1]) || $data[1] != PARAM_TOKEN_DELIMITER) {
return explode(PARAM_DELIMITER, $data);
}
$segments = explode(PARAM_DELIMITER, $data);
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
$attachment = array();
$flagConcat = false;
$flagSource = false;
$flagFilename = false;
foreach ($segments AS $line) {
// Check for deprecated token.
if ($line[0] == SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED) {
throw new UserFormException('Sendmail: Option "a:" is deprecated, please use "' . SENDMAIL_TOKEN_ATTACHMENT_FILE . '" instead', ERROR_UNKNOWN_TOKEN);
}
if (!isset($sendMailToken[$line[0]])) {
throw new UserReportException ("Unknown token in sendmail: " . $line, ERROR_UNKNOWN_TOKEN);
}
switch ($line[0]) {
case SENDMAIL_TOKEN_CONCAT:
$flagConcat = true;
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
}
break;
case SENDMAIL_TOKEN_ATTACHMENT_FILE:
case SENDMAIL_TOKEN_ATTACHMENT_URL:
case SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL:
if ($flagSource && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
$flagFilename = false;
}
$flagSource = true;
$attachment[] = $line;
break;
case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
if ($flagFilename && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
$flagSource = false;
}
$flagFilename = true;
$attachment[] = $line;
break;
default:
$idx = $sendMailToken[$line[0]];
if ($idx < 0 || $idx > count($sendMailToken)) {
throw new UserReportException('Invalid token in "sendmail": ' . $idx, ERROR_INVALID_VALUE);
}
$arr[$idx] = substr($line, 2);
break;
}
}
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
}
return ($arr);
}
}
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