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

Feature 4255 / AttachmentsInEmail: Implement 'concat'

parent ee3eb8ac
......@@ -32,12 +32,22 @@ class QfqController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
} catch (qfq\UserFormException $e) {
$html = $e->formatMessage();
} catch (qfq\UserReportException $e) {
$html = $e->formatMessage();
} catch (qfq\CodeException $e) {
$html = $e->formatMessage();
} catch (qfq\DbException $e) {
$html = $e->formatMessage();
} catch (qfq\ShellException $e) {
$html = $e->formatMessage();
} catch (qfq\DownloadException $e) {
$html = $e->formatMessage();
} catch (\Exception $e) {
$html = "Generic Exception: " . $e->getMessage();
}
......
......@@ -5245,10 +5245,12 @@ Easily create Email links.
Column: _sendmail
^^^^^^^^^^^^^^^^^
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]>
t:<TO:email[,email]>|F:<FROM:email>|s:<subject>|b:<body>
[|c:<CC:email[,email]]>[|B:<BCC:email[,email]]>[|F:<REPLY-TO:email>]
[|a:<flag autosubmit: on /off>][|g:<grid>][|x:<xId>][|y:<xId2>][|z:<xId3>]
[|C][d:<filename of the attachment>][|F:<file to attach>][|u:<url>][|U:<T3 uri>]
Send text emails. Every mail will be logged in the table `mailLog`.
Send text emails. Every mail will be logged in the table `mailLog`. Attachments are supported.
**Syntax**
......@@ -5260,7 +5262,7 @@ Send text emails. Every mail will be logged in the table `mailLog`.
..
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
|***Token** | **Parameter** |**Description** |**Required**|
|**Token** | **Parameter** |**Description** |**Required**|
+===+========================================+==================================================================================================+============+
| f | FROM:email |**FROM**: Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
......@@ -5278,7 +5280,15 @@ Send text emails. Every mail will be logged in the table `mailLog`.
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| h | Header |**Custom Header**: Separate multiple header with \r\n | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| a | Attachment |**Attachment**: Comma separated list of filenames to attach to the mail | |
| 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. | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| U | 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. | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| M | Merge multiple F|u|U| to one attachment|**Attachment**: All given 'F|u|U' concatenated to one attachment. Repeatable. | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| A | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
......@@ -5317,6 +5327,39 @@ Additional the CEO as well as backup will receive the mail via CC and BCC.
For debugging, please check `REDIRECT_ALL_MAIL_TO`_.
Attachment
''''''''''
The following types are provided:
* 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&...`.
* Optional any combination (incl. repeating) are possible. Any now 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.
* User definable filename for the attachment: `d:<filename>`.
Examples::
# 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
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 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
# 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
.. _column_img:
Column: _img
......
......@@ -467,7 +467,7 @@ const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS = 'RECORD_LOCK_TIMEOUT_SECONDS';
const SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS_DEFAULT = 900; // 15 mins
// Deprecated, replaced by SYSTEM_FILL_STORE_SYSTEM_BY_SQ
const SYSTEM_VAR_ADD_BY_SQL = 'VAR_ADD_BY_SQL';
const SYSTEM_VAR_ADD_BY_SQL = 'VAR_ADD_BY_SQL'; // since 1.12.17
//const SYSTEM_VAR_ADD_BY_SQL_DEFAULT = 'SELECT id AS periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1';
const SYSTEM_FILL_STORE_SYSTEM_BY_SQL = 'FILL_STORE_SYSTEM_BY_SQL';
......@@ -1091,13 +1091,13 @@ const SENDMAIL_TOKEN_X_ID = 'x';
const SENDMAIL_TOKEN_RECEIVER_CC = 'c';
const SENDMAIL_TOKEN_RECEIVER_BCC = 'B';
const SENDMAIL_TOKEN_ATTACHMENT_FILE = 'F';
const SENDMAIL_TOKEN_ATTACHMENT_DEPRECATED = 'a';
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_SRC = 'S';
const SENDMAIL_TOKEN_COMBINE = 'C';
const SENDMAIL_TOKEN_CONCAT = 'C';
const SENDMAIL_TOKEN_DOWNLOAD_FILENAME = 'd';
const SENDMAIL_TOKEN_ATTACHMENT_URL = 'u';
const SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL = 'U';
......@@ -1214,7 +1214,7 @@ const TOKEN_SIP = 's';
const TOKEN_URL_PARAM = 'U';
const TOKEN_RIGHT = 'R';
const TOKEN_FILE = 'F';
const TOKEN_FILE_DEPRECATED = 'f';
const TOKEN_FILE_DEPRECATED = 'f'; // since 5.12.17
const TOKEN_DOWNLOAD_MODE = 'M';
const TOKEN_ACTION_DELETE = 'x';
......
......@@ -18,9 +18,11 @@ class ErrorHandler {
// This error code is not included in error_reporting
return false;
}
// throw new CodeException(": Catchable Error in '$file' on line $line: " . $message . " - CWD: " . getcwd(), $severity, NULL);
// Do not show too much to the user. E.g. 'ldap_bind()' might have problems, but the user should not see the file and linenumber.
throw new CodeException($message, $severity, null);
// throw new CodeException($message, $severity, null);
return '';
}
}
\ No newline at end of file
......@@ -1272,6 +1272,7 @@ class Report {
*
* @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) {
......@@ -1285,10 +1286,10 @@ class Report {
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_HEADER => SENDMAIL_IDX_HEADER,
SENDMAIL_TOKEN_COMBINE => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_CONCAT => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_DOWNLOAD_FILENAME => SENDMAIL_IDX_ARRAY,
SENDMAIL_TOKEN_ATTACHMENT_FILE => SENDMAIL_IDX_ATTACHMENT,
SENDMAIL_TOKEN_ATTACHMENT_DEPRECATED => 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,
......@@ -1307,22 +1308,21 @@ class Report {
$segments = explode(PARAM_DELIMITER, $data);
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
$attachmentCombineOpen = false;
$attachment = array();
foreach ($segments AS $line) {
$piece = explode(PARAM_TOKEN_DELIMITER, $line, 2);
if (empty($piece[0])) {
throw new UserReportException ("Missing token in sendmail", ERROR_UNKNOWN_TOKEN);
}
$flagConcat = false;
$flagSource = false;
$flagFilename = false;
foreach ($segments AS $line) {
if (!isset($sendmailToken[$piece[0]])) {
throw new UserReportException ("Unknown token in sendmail: $piece[0]", ERROR_UNKNOWN_TOKEN);
if (!isset($sendmailToken[$line[0]])) {
throw new UserReportException ("Unknown token in sendmail: " . $line, ERROR_UNKNOWN_TOKEN);
}
switch ($piece[0]) {
case SENDMAIL_TOKEN_COMBINE:
$attachmentCombineOpen = true;
switch ($line[0]) {
case SENDMAIL_TOKEN_CONCAT:
$flagConcat = true;
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
......@@ -1330,28 +1330,39 @@ class Report {
break;
case SENDMAIL_TOKEN_ATTACHMENT_FILE:
case SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED:
case SENDMAIL_TOKEN_ATTACHMENT_URL:
case SENDMAIL_TOKEN_ATTACHMENT_URL_LOCAL:
case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
$val = empty($piece[1]) ? '' : $piece[1];
// $attachment[] = [$piece[0] => $val];
$attachment[] = $piece[0] . PARAM_TOKEN_DELIMITER . $val;
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[$piece[0]];
$arr[$idx] = empty($piece[1]) ? '' : $piece[1];
$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) && !$attachmentCombineOpen) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
$attachment = array();
}
}
if (!empty($attachment) && $attachmentCombineOpen) {
if (!empty($attachment)) {
$arr[SENDMAIL_IDX_ATTACHMENT][] = $attachment;
}
......
......@@ -8,6 +8,7 @@ require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../database/Database.php');
require_once(__DIR__ . '/../store/Store.php');
require_once(__DIR__ . '/../helper/Sanitize.php');
require_once(__DIR__ . '/../helper/HelperFile.php');
class Sendmail {
......@@ -99,6 +100,9 @@ class Sendmail {
$attachments = array();
foreach ($mailConfig as $key => $value) {
if (is_array($value)) {
continue;
}
$mailConfig[$key] = Support::escapeDoubleTick($value);
}
......
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