* Mail: do not stall (quick-)preview on mails without text-part e.g. PDF only

This commit is contained in:
ralf 2024-06-20 15:01:50 +02:00
parent bd0818b7e1
commit abf5c00923
3 changed files with 43 additions and 21 deletions

View File

@ -1709,6 +1709,7 @@ class Mail
((intval($mime_id) === 1) || !$mime_id) &&
($partdisposition !== 'attachment')) {
$_structure=$part;
try {
$this->fetchPartContents($uid, $_structure, false,true);
$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
$charSet = $part->getCharset();
@ -1722,6 +1723,10 @@ class Mail
$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
}
catch (\Exception $e) {
// mail probably has no text-part
}
}
//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
$cid = $part->getContentId();
if (empty($partdisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
@ -4893,9 +4898,14 @@ class Mail
if (empty($partToReturn)&&$_tryDecodingServerside===true)
{
error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in BINARY. Try BODY');
try {
$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
}
return ($partToReturn?$partToReturn:null);
catch(\Exception $e) {
// mail probably has no text-body
}
}
return $partToReturn ?: null;
}
/**
@ -4938,6 +4948,7 @@ class Mail
// RB: not sure what this is: preg_replace('/PropertyFile___$/','',$this->decodeMimePart($mimePartBody, $_structure->encoding, $this->getMimePartCharset($_structure))),
// Should not try to fetch if the content is already there (e.g. Smime encrypted message)
try {
if (empty($_structure->getContents())) $this->fetchPartContents($_uid, $_structure, $_stream, $_preserveSeen);
$bodyPart = array(
@ -4948,6 +4959,15 @@ class Mail
'charSet' => $_structure->getCharset(),
);
}
catch (\Exception $e) {
$bodyPart = array(
'error' => 1,
'body' => lang('Mail probably has no text-body').":\n\n".$e->getMessage(),
'mimeType' => 'text/plain', // make sure we do not return mimeType text/html
'charSet' => self::$displayCharset,
);
}
}
return $bodyPart;
}

View File

@ -345,6 +345,7 @@ mail common de E-Mail
mail acl mail de Zugriffsrechte
mail filter mail de Filter
mail filter rule mail de Filter-Regel
mail probably has no text-body mail de Die Mail hat vermutlich keinen Textteil
mail settings mail de E-Mail-Einstellungen
mail source mail de Nachrichten-Quelltext anzeigen
mail-address mail de E-Mail-Adresse

View File

@ -345,6 +345,7 @@ mail common en Mail
mail acl mail en Email access rights
mail filter mail en Filter
mail filter rule mail en Mail filter rule
mail probably has no text-body mail en Mail probably has no text-body
mail settings mail en Mail settings
mail source mail en Mail Source
mail-address mail en Mail-Address