From 77870442fe98a48fa2e98549266fac09fd3929a8 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Tue, 2 Sep 2014 13:54:22 +0400 Subject: [PATCH] Fixed MailSo header parsing --- .../v/0.0.0/app/libraries/MailSo/Config.php | 5 +++++ .../app/libraries/MailSo/Imap/ImapClient.php | 7 ++++++- .../app/libraries/MailSo/Mail/Message.php | 2 +- .../app/libraries/MailSo/Mime/Header.php | 21 +++++++++++++------ .../MailSo/Mime/HeaderCollection.php | 3 ++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Config.php b/rainloop/v/0.0.0/app/libraries/MailSo/Config.php index e7f5791d6..8487235ce 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Config.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Config.php @@ -43,6 +43,11 @@ class Config */ public static $MessageListDateFilter = 0; + /** + * @var int + */ + public static $LogSimpleLiterals = false; + /** * @var \MailSo\Log\Logger|null */ diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index b86d98ce5..96d0943ce 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -1929,10 +1929,15 @@ class ImapClient extends \MailSo\Net\NetClient $this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '. $iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); } - + if (!$bTreatAsAtom) { $aList[] = $sLiteral; + + if (\MailSo\Config::$LogSimpleLiterals) + { + $this->writeLog('{'.\strlen($sLiteral).'} '.$sLiteral, \MailSo\Log\Enumerations\Type::INFO); + } } } else diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Mail/Message.php b/rainloop/v/0.0.0/app/libraries/MailSo/Mail/Message.php index 5088203ef..8fe93dbbb 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Mail/Message.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Mail/Message.php @@ -619,7 +619,7 @@ class Message $sHeaders = $oFetchResponse->GetHeaderFieldsValue(); if (0 < \strlen($sHeaders)) { - $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders); + $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders, false, $sCharset); $sContentTypeCharset = $oHeaders->ParameterValue( \MailSo\Mime\Enumerations\Header::CONTENT_TYPE, diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Mime/Header.php b/rainloop/v/0.0.0/app/libraries/MailSo/Mime/Header.php index 3d8781b60..6558f678f 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Mime/Header.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Mime/Header.php @@ -44,10 +44,11 @@ class Header * @param string $sName * @param string $sValue * @param string $sEncodedValueForReparse + * @param string $sParentCharset = '' */ - private function __construct($sName, $sValue, $sEncodedValueForReparse) + private function __construct($sName, $sValue, $sEncodedValueForReparse, $sParentCharset = '') { - $this->sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1; + $this->sParentCharset = $sParentCharset; $this->initInputData($sName, $sValue, $sEncodedValueForReparse); } @@ -95,12 +96,13 @@ class Header * @param string $sName * @param string $sValue = '' * @param string $sEncodedValueForReparse = '' + * @param string $sParentCharset = '' * * @return \MailSo\Mime\Header */ - public static function NewInstance($sName, $sValue = '', $sEncodedValueForReparse = '') + public static function NewInstance($sName, $sValue = '', $sEncodedValueForReparse = '', $sParentCharset = '') { - return new self($sName, $sValue, $sEncodedValueForReparse); + return new self($sName, $sValue, $sEncodedValueForReparse, $sParentCharset); } /** @@ -111,13 +113,19 @@ class Header */ public static function NewInstanceFromEncodedString($sEncodedLines, $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) { + if (empty($sIncomingCharset)) + { + $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1; + } + $aParts = \explode(':', \str_replace("\r", '', $sEncodedLines), 2); if (isset($aParts[0]) && isset($aParts[1]) && 0 < \strlen($aParts[0]) && 0 < \strlen($aParts[1])) { return self::NewInstance( \trim($aParts[0]), \trim(\MailSo\Base\Utils::DecodeHeaderValue(\trim($aParts[1]), $sIncomingCharset)), - \trim($aParts[1]) + \trim($aParts[1]), + $sIncomingCharset ); } @@ -167,7 +175,8 @@ class Header $this->initInputData( $this->sName, \trim(\MailSo\Base\Utils::DecodeHeaderValue($this->sEncodedValueForReparse, $sParentCharset)), - $this->sEncodedValueForReparse); + $this->sEncodedValueForReparse + ); } $this->sParentCharset = $sParentCharset; diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Mime/HeaderCollection.php b/rainloop/v/0.0.0/app/libraries/MailSo/Mime/HeaderCollection.php index 35b8577ca..36f1bab56 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Mime/HeaderCollection.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Mime/HeaderCollection.php @@ -29,7 +29,7 @@ class HeaderCollection extends \MailSo\Base\Collection parent::__construct(); $this->sRawHeaders = ''; - $this->sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1; + $this->sParentCharset = ''; if (0 < \strlen($sRawHeaders)) { @@ -318,6 +318,7 @@ class HeaderCollection extends \MailSo\Base\Collection { $this->Add($oHeader); } + $sName = null; $sValue = null; }