mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 16:37:02 +03:00
Replace InlineBase64Decode with default convert.base64-decode and a WhitespaceFilter
This commit is contained in:
parent
5816c08e11
commit
8abf8844bc
1 changed files with 23 additions and 35 deletions
|
|
@ -11,6 +11,20 @@
|
||||||
|
|
||||||
namespace MailSo\Base\StreamWrappers;
|
namespace MailSo\Base\StreamWrappers;
|
||||||
|
|
||||||
|
|
||||||
|
class WhitespaceFilter extends \php_user_filter
|
||||||
|
{
|
||||||
|
function filter($in, $out, &$consumed, $closing)
|
||||||
|
{
|
||||||
|
while ($bucket = \stream_bucket_make_writeable($in)) {
|
||||||
|
$bucket->data = \str_replace(array("\r", "\n", "\t"), '', $bucket->data);
|
||||||
|
$consumed += $bucket->datalen;
|
||||||
|
\stream_bucket_append($out, $bucket);
|
||||||
|
}
|
||||||
|
return PSFS_PASS_ON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category MailSo
|
* @category MailSo
|
||||||
* @package Base
|
* @package Base
|
||||||
|
|
@ -70,20 +84,15 @@ class Binary
|
||||||
|
|
||||||
public static function GetInlineDecodeOrEncodeFunctionName(string $sContentTransferEncoding, bool $bDecode = true) : string
|
public static function GetInlineDecodeOrEncodeFunctionName(string $sContentTransferEncoding, bool $bDecode = true) : string
|
||||||
{
|
{
|
||||||
$sFunctionName = '';
|
|
||||||
switch (strtolower($sContentTransferEncoding))
|
switch (strtolower($sContentTransferEncoding))
|
||||||
{
|
{
|
||||||
case \MailSo\Base\Enumerations\Encoding::BASE64_LOWER:
|
case \MailSo\Base\Enumerations\Encoding::BASE64_LOWER:
|
||||||
// InlineBase64Decode
|
return $bDecode ? 'convert.base64-decode' : 'convert.base64-encode';
|
||||||
$sFunctionName = $bDecode ? 'InlineBase64Decode' : 'convert.base64-encode';
|
|
||||||
break;
|
|
||||||
case \MailSo\Base\Enumerations\Encoding::QUOTED_PRINTABLE_LOWER:
|
case \MailSo\Base\Enumerations\Encoding::QUOTED_PRINTABLE_LOWER:
|
||||||
// InlineQuotedPrintableDecode
|
return $bDecode ? 'convert.quoted-printable-decode' : 'convert.quoted-printable-encode';
|
||||||
$sFunctionName = $bDecode ? 'convert.quoted-printable-decode' : 'convert.quoted-printable-encode';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sFunctionName;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function InlineNullDecode(string $sBodyString, string &$sEndBuffer) : string
|
public static function InlineNullDecode(string $sBodyString, string &$sEndBuffer) : string
|
||||||
|
|
@ -92,33 +101,6 @@ class Binary
|
||||||
return $sBodyString;
|
return $sBodyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function InlineBase64Decode(string $sBaseString, string &$sEndBuffer) : string
|
|
||||||
{
|
|
||||||
$sEndBuffer = '';
|
|
||||||
$sBaseString = str_replace(array("\r", "\n", "\t"), '', $sBaseString);
|
|
||||||
$iBaseStringLen = strlen($sBaseString);
|
|
||||||
$iBaseStringNormFloorLen = floor($iBaseStringLen / 4) * 4;
|
|
||||||
if ($iBaseStringNormFloorLen < $iBaseStringLen)
|
|
||||||
{
|
|
||||||
$sEndBuffer = substr($sBaseString, $iBaseStringNormFloorLen);
|
|
||||||
$sBaseString = substr($sBaseString, 0, $iBaseStringNormFloorLen);
|
|
||||||
}
|
|
||||||
return \MailSo\Base\Utils::Base64Decode($sBaseString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function InlineQuotedPrintableDecode(string $sQuotedPrintableString, string &$sEndBuffer) : string
|
|
||||||
{
|
|
||||||
$sEndBuffer = '';
|
|
||||||
$sQuotedPrintableLen = strlen($sQuotedPrintableString);
|
|
||||||
$iLastSpace = strrpos($sQuotedPrintableString, ' ');
|
|
||||||
if (false !== $iLastSpace && $iLastSpace + 1 < $sQuotedPrintableLen)
|
|
||||||
{
|
|
||||||
$sEndBuffer = substr($sQuotedPrintableString, $iLastSpace + 1);
|
|
||||||
$sQuotedPrintableString = substr($sQuotedPrintableString, 0, $iLastSpace + 1);
|
|
||||||
}
|
|
||||||
return quoted_printable_decode($sQuotedPrintableString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function InlineConvertDecode(string $sEncodedString, string &$sEndBuffer, string $sFromEncoding, string $sToEncoding) : string
|
public static function InlineConvertDecode(string $sEncodedString, string &$sEndBuffer, string $sFromEncoding, string $sToEncoding) : string
|
||||||
{
|
{
|
||||||
$sEndBuffer = '';
|
$sEndBuffer = '';
|
||||||
|
|
@ -190,6 +172,12 @@ class Binary
|
||||||
'convert.quoted-printable-decode', 'convert.quoted-printable-encode'
|
'convert.quoted-printable-decode', 'convert.quoted-printable-encode'
|
||||||
)))
|
)))
|
||||||
{
|
{
|
||||||
|
if ('convert.base64-decode' === $sUtilsDecodeOrEncodeFunctionName) {
|
||||||
|
\stream_filter_register('mailsowhitespace', '\\MailSo\\Base\\StreamWrappers\\WhitespaceFilter');
|
||||||
|
if (!\stream_filter_append($rStream, 'mailsowhitespace')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName,
|
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName,
|
||||||
STREAM_FILTER_READ, array(
|
STREAM_FILTER_READ, array(
|
||||||
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
|
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue