Commit 905428db authored by Carsten  Rose's avatar Carsten Rose
Browse files

sendMail refactored - AutoCron.php,Report.php,SendMail.php: SENDMAIL_IDX_*...

sendMail refactored - AutoCron.php,Report.php,SendMail.php: SENDMAIL_IDX_* replaced by SENDMAIL_TOKEN_*
parent b00d7165
......@@ -177,20 +177,20 @@ class AutoCron {
if ($content == '' OR ($mailEntry[FE_SENDMAIL_TO] == '' AND $mailEntry[FE_SENDMAIL_CC] == '' AND $mailEntry[FE_SENDMAIL_BCC] == '')) {
continue; // no receiver: skip
}
$mail[SENDMAIL_IDX_RECEIVER] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_TO]);
$mail[SENDMAIL_IDX_SENDER] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_FROM]);
$mail[SENDMAIL_IDX_SUBJECT] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_SUBJECT]);
$mail[SENDMAIL_IDX_BODY] = $content;
$mail[SENDMAIL_IDX_REPLY_TO] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_REPLY_TO]);
$mail[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_FLAG_AUTO_SUBMIT]) === 'off' ? 'off' : 'on';
$mail[SENDMAIL_IDX_GR_ID] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_GR_ID]);
$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[SENDMAIL_TOKEN_RECEIVER] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_TO]);
$mail[SENDMAIL_TOKEN_SENDER] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_FROM]);
$mail[SENDMAIL_TOKEN_SUBJECT] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_SUBJECT]);
$mail[SENDMAIL_TOKEN_BODY] = $content;
$mail[SENDMAIL_TOKEN_REPLY_TO] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_REPLY_TO]);
$mail[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_FLAG_AUTO_SUBMIT]) === 'off' ? 'off' : 'on';
$mail[SENDMAIL_TOKEN_GR_ID] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_GR_ID]);
$mail[SENDMAIL_TOKEN_X_ID] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_X_ID]);
$mail[SENDMAIL_TOKEN_RECEIVER_CC] = $this->evaluate->parse($mailEntry[FE_SENDMAIL_CC]);
$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_SRC] = "AutoCron: Cron.id=" . $job[COLUMN_ID];
// Mail: send
$sendMail->process($mail);
......
......@@ -1064,23 +1064,6 @@ const COLUMN_PATH_FILE_NAME = 'pathFileName';
const EXISTING_PATH_FILE_NAME = '_existingPathFileName';
//SENDMAIL
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;
const SENDMAIL_IDX_BODY = 3;
const SENDMAIL_IDX_REPLY_TO = 4;
const SENDMAIL_IDX_FLAG_AUTO_SUBMIT = 5;
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_ATTACHMENT = 10;
const SENDMAIL_IDX_HEADER = 11;
const SENDMAIL_IDX_X_ID2 = 12;
const SENDMAIL_IDX_X_ID3 = 13;
const SENDMAIL_IDX_SRC = 14;
const SENDMAIL_TOKEN_RECEIVER = 't';
const SENDMAIL_TOKEN_SENDER = 'f';
const SENDMAIL_TOKEN_SUBJECT = 's';
......@@ -1091,6 +1074,7 @@ 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_ATTACHMENT = 'attachment';
const SENDMAIL_TOKEN_ATTACHMENT_FILE = 'F';
const SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED = 'a'; // since 5.12.17
const SENDMAIL_TOKEN_HEADER = 'h';
......
......@@ -773,7 +773,7 @@ class Report {
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL, null, __FILE__, __LINE__, $this->fr_error);
}
$mailConfig[SENDMAIL_IDX_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
$mailConfig[SENDMAIL_TOKEN_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
", T3 ttcontentId=" . $this->store->getVar('ttcontentUid', STORE_TYPO3) .
", Level=" . $full_level;
......
......@@ -7,6 +7,7 @@ namespace qfq;
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../database/Database.php');
require_once(__DIR__ . '/../store/Store.php');
require_once(__DIR__ . '/../report/Download.php');
require_once(__DIR__ . '/../helper/Sanitize.php');
require_once(__DIR__ . '/../helper/HelperFile.php');
......@@ -21,28 +22,9 @@ class SendMail {
/**
* Sends a mail as specified in $mailarr.
* If there is no receiver specified as 'TO': no mail is sent. This is ok and no error.
* Logs every send mail as a record in table `mailLog`. Additionally a `grId` and a `xId` can be specified
* Logs every send mail as a record in table `MailLog`. Additionally a `grId`, `xId` , `xId2` and `xId3` can be specified
* to assign the log entry to a specific action.
* The log record also contains some information which generates the mail (form/formelement or QFQ query).
*
* Structure mailarr:
* SENDMAIL_IDX_RECEIVER email address(es)
* SENDMAIL_IDX_SENDER email address
* SENDMAIL_IDX_SUBJECT string
* SENDMAIL_IDX_BODY string
* SENDMAIL_IDX_REPLY_TO optional: email address
* SENDMAIL_IDX_FLAG_AUTO_SUBMIT optional: 'on'|'off', default: 'on'
* SENDMAIL_IDX_GR_ID optional: integer
* SENDMAIL_IDX_X_ID optional: integer
* SENDMAIL_IDX_RECEIVER_CC optional: integer
* SENDMAIL_IDX_RECEIVER_BCC optional: integer
* SENDMAIL_IDX_ATTACHMENT optional: array, per attachment one sub array.
* SENDMAIL_IDX_HEADER optional: integer
* SENDMAIL_IDX_X_ID2 optional: integer
* SENDMAIL_IDX_X_ID3 optional: integer
* SENDMAIL_IDX_SRC optional: integer
*
* @param $mailConfig
* The log record also contains some information who/where generates the mail (form/formelement or QFQ query).
*
* @throws UserFormException
*/
......@@ -53,52 +35,47 @@ class SendMail {
/**
*
* @param array $mailConfig
* @throws UserFormException
*/
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] === '') {
if (!isset($mailConfig[SENDMAIL_TOKEN_RECEIVER]) || $mailConfig[SENDMAIL_TOKEN_RECEIVER] === '') {
return;
}
if (count($mailConfig) < 4 || $mailConfig[SENDMAIL_IDX_SENDER] === '' || $mailConfig[SENDMAIL_IDX_SUBJECT] === '' || $mailConfig[SENDMAIL_IDX_BODY] === '') {
if (count($mailConfig) < 4 || $mailConfig[SENDMAIL_TOKEN_SENDER] === '' || $mailConfig[SENDMAIL_TOKEN_SUBJECT] === '' || $mailConfig[SENDMAIL_TOKEN_BODY] === '') {
throw new UserFormException("Error sendmail missing one of: receiver, sender, subject or body", ERROR_SENDMAIL_MISSING_VALUE);
}
$this->store = Store::getInstance('');
$redirectAllMail = $this->store->getVar(SYSTEM_REDIRECT_ALL_MAIL_TO, STORE_SYSTEM);
if ($redirectAllMail !== false) {
$addBody = "All QFQ outgoing mails are catched and redirected to you." . PHP_EOL . "Original receiver:" . PHP_EOL;
$addBody .= 'TO: ' . $mailConfig[SENDMAIL_IDX_RECEIVER] . PHP_EOL;
$addBody .= 'CC: ' . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . PHP_EOL;
$addBody .= 'BCC: ' . $mailConfig[SENDMAIL_IDX_RECEIVER_BCC] . PHP_EOL;
$addBody .= 'TO: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . PHP_EOL;
$addBody .= 'CC: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] . PHP_EOL;
$addBody .= 'BCC: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC] . PHP_EOL;
$addBody .= PHP_EOL . "==========================================" . PHP_EOL . PHP_EOL;
$mailConfig[SENDMAIL_IDX_BODY] = $addBody . $mailConfig[SENDMAIL_IDX_BODY];
$mailConfig[SENDMAIL_TOKEN_BODY] = $addBody . $mailConfig[SENDMAIL_TOKEN_BODY];
$mailConfig[SENDMAIL_IDX_RECEIVER] = $redirectAllMail;
$mailConfig[SENDMAIL_IDX_RECEIVER_CC] = '';
$mailConfig[SENDMAIL_IDX_RECEIVER_BCC] = '';
$mailConfig[SENDMAIL_TOKEN_RECEIVER] = $redirectAllMail;
$mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] = '';
$mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC] = '';
}
if (empty($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === '') {
$mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = 'on';
if (empty($mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] === '') {
$mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] = 'on';
}
// $header = $this->buildHeader($mailarr);
// if (!(mb_send_mail($mailarr[SENDMAIL_IDX_RECEIVER], $mailarr[SENDMAIL_IDX_SUBJECT], $addBody . $mailarr[SENDMAIL_IDX_BODY], $header, "-f " . $mailarr[SENDMAIL_IDX_SENDER]))) {
// throw new UserFormException("Error sendmail failed.", ERROR_SENDMAIL);
// }
$attachmentsLine = $this->sendEmail($mailConfig);
$this->mailLog($mailConfig, $attachmentsLine);
$logAttachments = $this->sendEmail($mailConfig);
$this->mailLog($mailConfig, $logAttachments);
}
/**
* Use the programm 'sendEmail' - http://caspian.dotconf.net/menu/Software/SendEmail
* Body and Subject is UTF8 encoded,
*
* @param array $mailConfig
* @return string
......@@ -109,7 +86,7 @@ class SendMail {
private function sendEmail(array $mailConfig) {
$args = array();
$attachments = array();
$attachmentsLine = '';
$cmdAttachments = '';
foreach ($mailConfig as $key => $value) {
if (is_array($value)) {
......@@ -118,8 +95,8 @@ class SendMail {
$mailConfig[$key] = Support::escapeDoubleTick($value);
}
$args[] = '-f "' . $mailConfig[SENDMAIL_IDX_SENDER] . '"';
$args[] = '-t "' . $mailConfig[SENDMAIL_IDX_RECEIVER] . '"';
$args[] = '-f "' . $mailConfig[SENDMAIL_TOKEN_SENDER] . '"';
$args[] = '-t "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . '"';
$args[] = '-o message-charset="utf-8"';
$logFile = $this->store->getVar(SYSTEM_MAIL_LOG, STORE_SYSTEM);
......@@ -127,49 +104,45 @@ class SendMail {
$args[] = '-l "' . $logFile . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_RECEIVER_CC])) {
$args[] = '-cc "' . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . '"';;
if (!empty($mailConfig[SENDMAIL_TOKEN_RECEIVER_CC])) {
$args[] = '-cc "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_RECEIVER_BCC])) {
$args[] = '-bcc "' . $mailConfig[SENDMAIL_IDX_RECEIVER_BCC];
if (!empty($mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC])) {
$args[] = '-bcc "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC];
}
if (!empty($mailConfig[SENDMAIL_IDX_SUBJECT])) {
if (!empty($mailConfig[SENDMAIL_TOKEN_SUBJECT])) {
// The subject needs to be encoded to UTF-8 separately - https://stackoverflow.com/questions/4389676/email-from-php-has-broken-subject-header-encoding/27648245#27648245
$preferences = ["scheme" => "Q", "input-charset" => "UTF-8", "output-charset" => "UTF-8"];
$encodedSubject = iconv_mime_encode("Subject", $mailConfig[SENDMAIL_IDX_SUBJECT], $preferences);
$encodedSubject = iconv_mime_encode("Subject", $mailConfig[SENDMAIL_TOKEN_SUBJECT], $preferences);
$encodedSubject = substr($encodedSubject, 9); // remove 'Subject: '
$args[] = '-u "' . $encodedSubject . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_BODY])) {
$args[] = '-m "' . $mailConfig[SENDMAIL_IDX_BODY] . '"';;
if (!empty($mailConfig[SENDMAIL_TOKEN_BODY])) {
$args[] = '-m "' . $mailConfig[SENDMAIL_TOKEN_BODY] . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_REPLY_TO])) {
$args[] = '-o reply-to="' . $mailConfig[SENDMAIL_IDX_REPLY_TO] . '"';;
if (!empty($mailConfig[SENDMAIL_TOKEN_REPLY_TO])) {
$args[] = '-o reply-to="' . $mailConfig[SENDMAIL_TOKEN_REPLY_TO] . '"';;
}
if ($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === 'on') {
if ($mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] === 'on') {
$args[] = '-o message-header="Auto-Submitted: auto-send"';
}
if (!empty($mailConfig[SENDMAIL_IDX_ATTACHMENT])) {
// $pieces = explode(',', $mailConfig[SENDMAIL_IDX_ATTACHMENT]);
// foreach ($pieces as $piece) {
// $args[] = '-a ' . $piece;
// }
$attachments = $this->attachmentsBuild($mailConfig[SENDMAIL_IDX_ATTACHMENT]);
if (!empty($mailConfig[SENDMAIL_TOKEN_ATTACHMENT])) {
$attachments = $this->attachmentsBuild($mailConfig[SENDMAIL_TOKEN_ATTACHMENT]);
if (!empty($attachments)) {
$attachmentsLine = '-a ' . implode(' -a ', $attachments);
$args[] = $attachmentsLine;
$cmdAttachments = '-a ' . implode(' -a ', $attachments);
$args[] = $cmdAttachments;
}
}
if (!empty($mailConfig[SENDMAIL_IDX_HEADER])) {
$args[] = '-o message-header="' . $mailConfig[SENDMAIL_IDX_HEADER] . '"';
if (!empty($mailConfig[SENDMAIL_TOKEN_HEADER])) {
$args[] = '-o message-header="' . $mailConfig[SENDMAIL_TOKEN_HEADER] . '"';
}
$sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL, STORE_SYSTEM);
......@@ -188,7 +161,7 @@ class SendMail {
exec($cmd, $arr, $rc);
if ($rc != 0) {
// After first installation of QFQ extension, the PERL script is not executable: is this the case?
// After first installation of QFQ extension, the PERL script is not executable: is this the problem here?
$perms = fileperms($sendEmail);
if (!($perms & 0x0040)) {
chmod($sendEmail, 0755);
......@@ -203,7 +176,7 @@ class SendMail {
HelperFile::cleanTempFiles($attachments);
return $attachmentsLine;
return $cmdAttachments;
}
/**
......@@ -218,26 +191,26 @@ class SendMail {
$log = array();
$header = 'OoO:' . $mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT];
if (!empty($mailConfig[SENDMAIL_IDX_HEADER])) {
$header .= PHP_EOL . 'Custom: ' . $mailConfig[SENDMAIL_IDX_HEADER];
$header = 'OoO:' . $mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT];
if (!empty($mailConfig[SENDMAIL_TOKEN_HEADER])) {
$header .= PHP_EOL . 'Custom: ' . $mailConfig[SENDMAIL_TOKEN_HEADER];
}
if (!empty($mailConfig[SENDMAIL_IDX_ATTACHMENT])) {
$header .= PHP_EOL . 'Attachment: ' . $mailConfig[SENDMAIL_IDX_ATTACHMENT];
if (!empty($mailConfig[SENDMAIL_TOKEN_ATTACHMENT])) {
$header .= PHP_EOL . 'Attachment: ' . $mailConfig[SENDMAIL_TOKEN_ATTACHMENT];
}
// Log
$log[] = $mailConfig[SENDMAIL_IDX_RECEIVER];
$log[] = $mailConfig[SENDMAIL_IDX_SENDER];
$log[] = $mailConfig[SENDMAIL_IDX_SUBJECT];
$log[] = $mailConfig[SENDMAIL_IDX_BODY];
$log[] = $mailConfig[SENDMAIL_TOKEN_RECEIVER];
$log[] = $mailConfig[SENDMAIL_TOKEN_SENDER];
$log[] = $mailConfig[SENDMAIL_TOKEN_SUBJECT];
$log[] = $mailConfig[SENDMAIL_TOKEN_BODY];
$log[] = $header;
$log[] = $attachmentsLine;
$log[] = empty($mailConfig[SENDMAIL_IDX_GR_ID]) ? 0 : $mailConfig[SENDMAIL_IDX_GR_ID];
$log[] = empty($mailConfig[SENDMAIL_IDX_X_ID]) ? 0 : $mailConfig[SENDMAIL_IDX_X_ID];
$log[] = empty($mailConfig[SENDMAIL_IDX_X_ID2]) ? 0 : $mailConfig[SENDMAIL_IDX_X_ID2];
$log[] = empty($mailConfig[SENDMAIL_IDX_X_ID3]) ? 0 : $mailConfig[SENDMAIL_IDX_X_ID3];
$log[] = empty($mailConfig[SENDMAIL_IDX_SRC]) ? 0 : $mailConfig[SENDMAIL_IDX_SRC];
$log[] = empty($mailConfig[SENDMAIL_TOKEN_GR_ID]) ? 0 : $mailConfig[SENDMAIL_TOKEN_GR_ID];
$log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID];
$log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID2]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID2];
$log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID3]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID3];
$log[] = empty($mailConfig[SENDMAIL_TOKEN_SRC]) ? 0 : $mailConfig[SENDMAIL_TOKEN_SRC];
$db = new Database();
$db->sql('INSERT INTO MailLog (`receiver`, `sender`, `subject`, `body`, `header`, `attach`, `grId`, `xId`, `xId2`, `xId3`, `src`, `modified`, `created`) VALUES ( ?, ? , ? , ? ,?, ?, ? ,?, ?, ?, ?, NOW(), NOW() )', ROW_REGULAR, $log);
......@@ -346,58 +319,38 @@ class SendMail {
*/
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 = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
$args = array();
$attachment = array();
$flagConcat = false;
$flagSource = false;
$flagFilename = false;
foreach ($segments AS $line) {
$param = explode(PARAM_DELIMITER, $data);
// 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);
// Iterate over all parameter: use token as key. Collect corresponding attachments arguments in separate array elements
foreach ($param AS $line) {
if (empty($line)) {
continue;
}
$token = $line[0];
if (strlen($line) > 2 && $line[1] != PARAM_TOKEN_DELIMITER) {
throw new UserFormException('Missing token delimiter "' . PARAM_TOKEN_DELIMITER . '" in: ' . $line, ERROR_UNKNOWN_TOKEN);
}
if (!isset($sendMailToken[$line[0]])) {
throw new UserReportException ("Unknown token in sendmail: " . $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);
}
switch ($line[0]) {
switch ($token) {
case SENDMAIL_TOKEN_CONCAT:
$flagConcat = true;
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
$attachment = array();
}
break;
......@@ -406,7 +359,7 @@ class SendMail {
case SENDMAIL_TOKEN_ATTACHMENT_URL:
case SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL:
if ($flagSource && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
$attachment = array();
$flagFilename = false;
}
......@@ -416,7 +369,7 @@ class SendMail {
case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
if ($flagFilename && !$flagConcat) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
$attachment = array();
$flagSource = false;
}
......@@ -425,20 +378,16 @@ class SendMail {
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);
$args[$token] = substr($line, 2);
break;
}
}
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
}
return ($arr);
return ($args);
}
}
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