Cleanup attachment filenames

This commit is contained in:
djmaze 2021-12-16 16:29:31 +01:00
parent 94bfe09f63
commit 7df3ed665d
3 changed files with 7 additions and 6 deletions

View file

@ -9,6 +9,7 @@ const
msOffice = app+'vnd.openxmlformats-officedocument.',
openDoc = app+'vnd.oasis.opendocument.',
sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB'],
lowerCase = text => text.toLowerCase().trim(),
exts = {
eml: 'message/rfc822',
@ -123,13 +124,13 @@ export const FileInfo = {
* @returns {string}
*/
getExtension: fileName => {
fileName = fileName.toLowerCase().trim();
fileName = lowerCase(fileName);
const result = fileName.split('.').pop();
return result === fileName ? '' : result;
},
getContentType: fileName => {
fileName = fileName.toLowerCase().trim();
fileName = lowerCase(fileName);
if ('winmail.dat' === fileName) {
return app + 'ms-tnef';
}
@ -158,8 +159,8 @@ export const FileInfo = {
* @returns {string}
*/
getType: (ext, mimeType) => {
ext = ext.toLowerCase().trim();
mimeType = mimeType.toLowerCase().trim().replace('csv/plain', 'text/csv');
ext = lowerCase(ext);
mimeType = lowerCase(mimeType).replace('csv/plain', 'text/csv');
let key = ext + mimeType;
if (cache[key]) {

View file

@ -67,7 +67,7 @@ class Attachment implements \JsonSerializable
if ($this->oBodyStructure)
{
$sFileName = $this->oBodyStructure->FileName();
if ($bCalculateOnEmpty && 0 === \strlen(trim($sFileName)))
if ($bCalculateOnEmpty && !\strlen(\trim($sFileName)))
{
$sMimeType = \strtolower(\trim($this->MimeType()));
if ('message/rfc822' === $sMimeType)

View file

@ -29,7 +29,7 @@ class AttachmentCollection extends \MailSo\Base\Collection
foreach ($this as $oAttachment) {
$aResult[] = array(
'@Object' => 'Object/Attachment',
'FileName' => $oAttachment->FileName(true),
'FileName' => $oAttachment->FileName(),
'MimeType' => $oAttachment->MimeType(),
'IsInline' => $oAttachment->IsInline()
);