Recipients List CSV Export fails in TYPO3 9 (direct_mail 6.0.2)
Hi there, a customer using TYPO3 v9.5.31 and direct_mail v6.0.2 on PHP 7.3 reported to me that they can't export any recipients lists from the Direct Mail 'Recipients List' backend module. When selecting a list and choosing "Download CSV file", I get a PHP warning saying:
PHP Warning: fputcsv(): enclosure must be a character in /var/www/html/htdocs/web/typo3/sysext/core/Classes/Utility/CsvUtility.php line 111
The stack trace shows:
at fputcsv(resource, array(' uid', ' name', ' first_name', ' middle_name', ' last_name', ' title', ' email', ' phone', ' www', ' address', ' company', ' city', ' zip', ' country', ' fax', ' module_sys_dmail_category', ' module_sys_dmail_html', ' tstamp'), ',', '')
in /var/www/html/htdocs/web/typo3/sysext/core/Classes/Utility/CsvUtility.php line 111
$row = array_map([self::class, 'removeControlLiterals'], $row);
} elseif ($type === self::TYPE_PREFIX_CONTROLS) {
$row = array_map([self::class, 'prefixControlLiterals'], $row);
}
fputcsv($resource, $modifier($row), $delim, $quote);
fseek($resource, 0);
$content = stream_get_contents($resource);
return $content;
}
at TYPO3\CMS\Core\Utility\CsvUtility::csvValues(array('uid', 'name', 'first_name', 'middle_name', 'last_name', 'title', 'email', 'phone', 'www', 'address', 'company', 'city', 'zip', 'country', 'fax', 'module_sys_dmail_category', 'module_sys_dmail_html', 'tstamp'), ',', '')
in /var/www/html/htdocs/web/typo3conf/ext/direct_mail/Classes/Module/RecipientList.php line 811
{
$lines = array();
if (is_array($idArr) && count($idArr)) {
reset($idArr);
$lines[] = CsvUtility::csvValues(array_keys(current($idArr)), ',', '');
reset($idArr);
foreach ($idArr as $rec) {
$lines[] = CsvUtility::csvValues($rec);
(the characters look funky but I am 99.9% sure they don't have anything to do with this issue)
I have tried this in different environments running TYPO3v9 and this behaviour seems to be consistent. This affects every list I am trying to export, no matter how many entries it contains.
We are also running direct_mail on TYPO3 8.7 ELTS and there is no problem with the recipients CSV export.
After some digging I found that between TYPO3 v8 and v9 the method TYPO3\CMS\Core\Utility\CsvUtility::csvValues has changed: TYPO3 v8: https://git.typo3.org/typo3/typo3/-/blob/v8.7.32/typo3/sysext/core/Classes/Utility/CsvUtility.php#L79 TYPO3 v9: https://git.typo3.org/typo3/typo3/-/blob/9.5/typo3/sysext/core/Classes/Utility/CsvUtility.php#L98
As shown in the error trace, the function downloadCSV inside the RecipientList calls the CsvUtility::csvValues function with an empty string as enclosure parameter, which causes fputcsv to fail. RecipientList.php (current development version): https://github.com/kartolo/direct_mail/blob/develop/Classes/Module/RecipientList.php#L840 (v 6.0.2): https://github.com/kartolo/direct_mail/blob/6.0/Classes/Module/RecipientList.php#L806
Since the method has not changed in the recent version, there might be problems with the current version and TYPO3 v10 as well - don't have any TYPO3v10 with direct_mail running so I can't confirm it myself but it may be worth checking.
Can someone confirm this bug?
Not sure how to fix it properly as this functionality sits pretty deep and I am unsure about possible side effects. My first guess would be somehow copying the csvValues function of TYPO3 v8 into direct_mail and using that?
Thank you!
Can confirm. Also exists in typo3 v10.4.23.
Issue is your mentioned Classes/Module/RecipientList.php:840 which should use chr(8) instead of '' to enforce no enclosures.
(see: https://stackoverflow.com/questions/16896923/how-can-you-use-fgetcsv-when-there-is-no-enclosure-character/16897250)
Fix is personally confirmed by locally patching this line.