Added IMAP body text limit

This commit is contained in:
RainLoop Team 2014-07-18 15:32:03 +04:00
parent 037f4dc61c
commit 0fc8967a7f
5 changed files with 59 additions and 10 deletions

View file

@ -407,6 +407,7 @@ class HtmlUtils
$aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(), $aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(),
$bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false, $fAdditionalExternalFilter = null) $bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false, $fAdditionalExternalFilter = null)
{ {
$sResult = '';
$sHtml = null === $sHtml ? '' : (string) $sHtml; $sHtml = null === $sHtml ? '' : (string) $sHtml;
$sHtml = \trim($sHtml); $sHtml = \trim($sHtml);
if (0 === \strlen($sHtml)) if (0 === \strlen($sHtml))
@ -591,10 +592,10 @@ class HtmlUtils
$oElement->setAttribute('data-x-src', $sSrc); $oElement->setAttribute('data-x-src', $sSrc);
if ($fAdditionalExternalFilter) if ($fAdditionalExternalFilter)
{ {
$sResult = \call_user_func($fAdditionalExternalFilter, $sSrc); $sCallResult = \call_user_func($fAdditionalExternalFilter, $sSrc);
if (0 < \strlen($sResult)) if (0 < \strlen($sCallResult))
{ {
$oElement->setAttribute('data-x-additional-src', $sResult); $oElement->setAttribute('data-x-additional-src', $sCallResult);
} }
} }
} }

View file

@ -337,7 +337,8 @@ class MailClient
* @param string $sFolderName * @param string $sFolderName
* @param int $iIndex * @param int $iIndex
* @param bool $bIndexIsUid = true * @param bool $bIndexIsUid = true
* @param mixed $oCacher = null * @param \MailSo\Cache\CacheClient $oCacher = null
* @param int $iBodyTextLimit = null
* *
* @return \MailSo\Mail\Message|false * @return \MailSo\Mail\Message|false
* *
@ -345,7 +346,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = null) public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = null, $iBodyTextLimit = null)
{ {
if (!\MailSo\Base\Validator::RangeInt($iIndex, 1)) if (!\MailSo\Base\Validator::RangeInt($iIndex, 1))
{ {
@ -356,7 +357,9 @@ class MailClient
$oBodyStructure = null; $oBodyStructure = null;
$oMessage = false; $oMessage = false;
$aBodyPeekMimeIndexes = array(); $aBodyPeekMimeIndexes = array();
$aSignatureMimeIndexes = array();
$aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid); $aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid);
if (0 < \count($aFetchResponse) && isset($aFetchResponse[0])) if (0 < \count($aFetchResponse) && isset($aFetchResponse[0]))
@ -369,7 +372,7 @@ class MailClient
{ {
foreach ($aTextParts as $oPart) foreach ($aTextParts as $oPart)
{ {
$aBodyPeekMimeIndexes[] = $oPart->PartID(); $aBodyPeekMimeIndexes[] = array($oPart->PartID(), $oPart->Size());
} }
} }
@ -378,7 +381,7 @@ class MailClient
{ {
foreach ($aSignatureParts as $oPart) foreach ($aSignatureParts as $oPart)
{ {
$aBodyPeekMimeIndexes[] = $oPart->PartID(); $aSignatureMimeIndexes[] = $oPart->PartID();
} }
} }
} }
@ -395,7 +398,21 @@ class MailClient
if (0 < \count($aBodyPeekMimeIndexes)) if (0 < \count($aBodyPeekMimeIndexes))
{ {
foreach ($aBodyPeekMimeIndexes as $sTextMimeIndex) foreach ($aBodyPeekMimeIndexes as $aTextMimeData)
{
$sLine = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$aTextMimeData[0].']';
if (\is_numeric($iBodyTextLimit) && 0 < $iBodyTextLimit && $iBodyTextLimit < $aTextMimeData[1])
{
$sLine .= '<0.'.((int) $iBodyTextLimit).'>';
}
$aFetchItems[] = $sLine;
}
}
if (0 < \count($aSignatureMimeIndexes))
{
foreach ($aSignatureMimeIndexes as $sTextMimeIndex)
{ {
$aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$sTextMimeIndex.']'; $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$sTextMimeIndex.']';
} }
@ -1467,7 +1484,7 @@ class MailClient
/** /**
* @param string $sFolderName * @param string $sFolderName
* @param string $sFolderHash * @param string $sFolderHash
* @param mixed $oCacher * @param \MailSo\Cache\CacheClient $oCacher
* *
* @return array * @return array
* *

View file

@ -163,6 +163,11 @@ class Message
*/ */
private $iThreadsLen; private $iThreadsLen;
/**
* @var bool
*/
private $bTextPartIsTrimmed;
/** /**
* @var string * @var string
*/ */
@ -229,6 +234,8 @@ class Message
$this->iThreadsLen = 0; $this->iThreadsLen = 0;
$this->iParentThread = 0; $this->iParentThread = 0;
$this->bTextPartIsTrimmed = false;
$this->sPgpSignature = ''; $this->sPgpSignature = '';
$this->bPgpSigned = false; $this->bPgpSigned = false;
$this->bPgpEncrypted = false; $this->bPgpEncrypted = false;
@ -558,6 +565,14 @@ class Message
$this->iParentThread = $iParentThread; $this->iParentThread = $iParentThread;
} }
/**
* @return boole
*/
public function TextPartIsTrimmed()
{
return $this->bTextPartIsTrimmed;
}
/** /**
* @param string $sFolder * @param string $sFolder
* @param \MailSo\Imap\FetchResponse $oFetchResponse * @param \MailSo\Imap\FetchResponse $oFetchResponse
@ -774,6 +789,15 @@ class Message
foreach ($aTextParts as $oPart) foreach ($aTextParts as $oPart)
{ {
$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().']'); $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().']');
if (null === $sText)
{
$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().']<0>');
if (\is_string($sText) && 0 < \strlen($sText))
{
$this->bTextPartIsTrimmed = true;
}
}
if (\is_string($sText) && 0 < \strlen($sText)) if (\is_string($sText) && 0 < \strlen($sText))
{ {
$sTextCharset = $oPart->Charset(); $sTextCharset = $oPart->Charset();

View file

@ -5425,7 +5425,9 @@ class Actions
try try
{ {
$oMessage = $this->MailClient()->Message($sFolder, $iUid, true, $oMessage = $this->MailClient()->Message($sFolder, $iUid, true,
!!$this->Config()->Get('labs', 'use_imap_thread', false) ? $this->Cacher() : null); !!$this->Config()->Get('labs', 'use_imap_thread', false) ? $this->Cacher() : null,
(int) $this->Config()->Get('labs', 'imap_body_text_limit', 0)
);
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
@ -7082,6 +7084,8 @@ class Actions
$mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags); $mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
$mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags); $mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
$mResult['TextPartIsTrimmed'] = false;
if ('Message' === $sParent) if ('Message' === $sParent)
{ {
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments(); $oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
@ -7142,6 +7146,8 @@ class Actions
$mResult['TextHash'] = \md5($mResult['Html'].$mResult['Plain'].$mResult['PlainRaw']); $mResult['TextHash'] = \md5($mResult['Html'].$mResult['Plain'].$mResult['PlainRaw']);
$mResult['TextPartIsTrimmed'] = $mResponse->TextPartIsTrimmed();
$mResult['PgpSigned'] = $mResponse->PgpSigned(); $mResult['PgpSigned'] = $mResponse->PgpSigned();
$mResult['PgpEncrypted'] = $mResponse->PgpEncrypted(); $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();
$mResult['PgpSignature'] = $mResponse->PgpSignature(); $mResult['PgpSignature'] = $mResponse->PgpSignature();

View file

@ -232,6 +232,7 @@ Enables caching in the system'),
'use_imap_auth_plain' => array(false), 'use_imap_auth_plain' => array(false),
'imap_forwarded_flag' => array('$Forwarded'), 'imap_forwarded_flag' => array('$Forwarded'),
'imap_read_receipt_flag' => array('$ReadReceipt'), 'imap_read_receipt_flag' => array('$ReadReceipt'),
'imap_body_text_limit' => array(555000),
'smtp_show_server_errors' => array(false), 'smtp_show_server_errors' => array(false),
'curl_proxy' => array(''), 'curl_proxy' => array(''),
'curl_proxy_auth' => array(''), 'curl_proxy_auth' => array(''),