* 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,18 +1709,23 @@ class Mail
((intval($mime_id) === 1) || !$mime_id) &&
($partdisposition !== 'attachment')) {
$_structure=$part;
$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();
// check if client set a wrong charset and content is utf-8 --> use utf-8
if (strtolower($charSet) !='utf-8' && preg_match('//u', $headerObject['BODYPREVIEW']))
{
$charSet = 'UTF-8';
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();
// check if client set a wrong charset and content is utf-8 --> use utf-8
if (strtolower($charSet) !='utf-8' && preg_match('//u', $headerObject['BODYPREVIEW']))
{
$charSet = 'UTF-8';
}
// add line breaks to $bodyParts
//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
}
catch (\Exception $e) {
// mail probably has no text-part
}
// add line breaks to $bodyParts
//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
}
//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
$cid = $part->getContentId();
@ -4893,9 +4898,14 @@ class Mail
if (empty($partToReturn)&&$_tryDecodingServerside===true)
{
error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in BINARY. Try BODY');
$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
try {
$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
}
catch(\Exception $e) {
// mail probably has no text-body
}
}
return ($partToReturn?$partToReturn:null);
return $partToReturn ?: null;
}
/**
@ -4938,15 +4948,25 @@ 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)
if (empty($_structure->getContents())) $this->fetchPartContents($_uid, $_structure, $_stream, $_preserveSeen);
try {
if (empty($_structure->getContents())) $this->fetchPartContents($_uid, $_structure, $_stream, $_preserveSeen);
$bodyPart = array(
'body' => $_structure->getContents(array(
'stream' => $_stream,
)),
'mimeType' => $_structure->getType() == 'text/html' ? 'text/html' : 'text/plain',
'charSet' => $_structure->getCharset(),
);
$bodyPart = array(
'body' => $_structure->getContents(array(
'stream' => $_stream,
)),
'mimeType' => $_structure->getType() == 'text/html' ? 'text/html' : 'text/plain',
'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