mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-07 15:27:43 +08:00
Cleanup StreamWrappers and no need for WhitespaceFilter
This commit is contained in:
parent
1be93d7288
commit
80f5373e9e
6 changed files with 28 additions and 72 deletions
|
@ -12,19 +12,6 @@
|
|||
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
|
||||
* @package Base
|
||||
|
@ -149,11 +136,6 @@ class Binary
|
|||
public static function CreateStream($rStream,
|
||||
string $sUtilsDecodeOrEncodeFunctionName = null, string $sFromEncoding = null, string $sToEncoding = null)
|
||||
{
|
||||
if (!\in_array(self::STREAM_NAME, \stream_get_wrappers()))
|
||||
{
|
||||
\stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Binary');
|
||||
}
|
||||
|
||||
if (null === $sUtilsDecodeOrEncodeFunctionName || !\strlen($sUtilsDecodeOrEncodeFunctionName))
|
||||
{
|
||||
$sUtilsDecodeOrEncodeFunctionName = 'InlineNullDecode';
|
||||
|
@ -167,23 +149,18 @@ class Binary
|
|||
$sUtilsDecodeOrEncodeFunctionName = 'InlineConvertDecode';
|
||||
}
|
||||
|
||||
if (\in_array($sUtilsDecodeOrEncodeFunctionName, array(
|
||||
'convert.base64-decode', 'convert.base64-encode',
|
||||
'convert.quoted-printable-decode', 'convert.quoted-printable-encode'
|
||||
)))
|
||||
if (\in_array($sUtilsDecodeOrEncodeFunctionName, ['convert.base64-decode', 'convert.quoted-printable-decode']))
|
||||
{
|
||||
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName);
|
||||
return \is_resource($rFilter) ? $rStream : false;
|
||||
}
|
||||
else if (\in_array($sUtilsDecodeOrEncodeFunctionName, ['convert.base64-encode', '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,
|
||||
STREAM_FILTER_READ, array(
|
||||
\STREAM_FILTER_READ, array(
|
||||
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
|
||||
'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF
|
||||
));
|
||||
|
||||
return \is_resource($rFilter) ? $rStream : false;
|
||||
}
|
||||
|
||||
|
@ -333,3 +310,5 @@ class Binary
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
\stream_wrapper_register(Binary::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Binary');
|
||||
|
|
|
@ -50,11 +50,6 @@ class Literal
|
|||
*/
|
||||
public static function CreateStream($rStream, int $iLiteralLen)
|
||||
{
|
||||
if (!\in_array(self::STREAM_NAME, stream_get_wrappers()))
|
||||
{
|
||||
\stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Literal');
|
||||
}
|
||||
|
||||
$sHashName = \md5(\microtime(true).\rand(1000, 9999));
|
||||
|
||||
self::$aStreams[$sHashName] = array($rStream, $iLiteralLen);
|
||||
|
@ -163,3 +158,5 @@ class Literal
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
\stream_wrapper_register(Literal::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Literal');
|
||||
|
|
|
@ -58,11 +58,6 @@ class SubStreams
|
|||
*/
|
||||
public static function CreateStream(array $aSubStreams)
|
||||
{
|
||||
if (!\in_array(self::STREAM_NAME, \stream_get_wrappers()))
|
||||
{
|
||||
\stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\SubStreams');
|
||||
}
|
||||
|
||||
$sHashName = \MailSo\Base\Utils::Sha1Rand();
|
||||
|
||||
self::$aStreams[$sHashName] = \array_map(function ($mItem) {
|
||||
|
@ -219,3 +214,5 @@ class SubStreams
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
\stream_wrapper_register(SubStreams::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\SubStreams');
|
||||
|
|
|
@ -33,21 +33,11 @@ class TempFile
|
|||
*/
|
||||
private $rSream;
|
||||
|
||||
public static function Reg()
|
||||
{
|
||||
if (!in_array(self::STREAM_NAME, stream_get_wrappers()))
|
||||
{
|
||||
stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\TempFile');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource|bool
|
||||
*/
|
||||
public static function CreateStream(string $sHash, string &$sFileName = '')
|
||||
{
|
||||
self::Reg();
|
||||
|
||||
$sFileName = self::STREAM_NAME.'://'.$sHash;
|
||||
return fopen($sFileName, 'r+b');
|
||||
}
|
||||
|
@ -121,3 +111,5 @@ class TempFile
|
|||
return fseek($this->rSream, $iOffset, $iWhence);
|
||||
}
|
||||
}
|
||||
|
||||
\stream_wrapper_register(TempFile::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\TempFile');
|
||||
|
|
|
@ -39,11 +39,6 @@ class Test
|
|||
*/
|
||||
public static function CreateStream(string $sRawResponse)
|
||||
{
|
||||
if (!\in_array(self::STREAM_NAME, \stream_get_wrappers()))
|
||||
{
|
||||
\stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Test');
|
||||
}
|
||||
|
||||
$sHashName = \md5(\microtime(true).\rand(1000, 9999));
|
||||
|
||||
$rConnect = \fopen('php://memory', 'r+b');
|
||||
|
@ -106,3 +101,5 @@ class Test
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
\stream_wrapper_register(Test::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\Test');
|
||||
|
|
|
@ -226,7 +226,7 @@ class MailClient
|
|||
|
||||
$sFileName = '';
|
||||
$sContentType = '';
|
||||
$sMailEncodingName = '';
|
||||
$sMailEncoding = '';
|
||||
|
||||
$sMimeIndex = trim($sMimeIndex);
|
||||
$aFetchResponse = $this->oImapClient->Fetch(array(
|
||||
|
@ -250,22 +250,19 @@ class MailClient
|
|||
if (\strlen($sMimeIndex))
|
||||
{
|
||||
$sFileName = $oHeaders->ParameterValue(MimeHeader::CONTENT_DISPOSITION, MimeParameter::FILENAME);
|
||||
|
||||
if (!\strlen($sFileName))
|
||||
{
|
||||
if (!\strlen($sFileName)) {
|
||||
$sFileName = $oHeaders->ParameterValue(MimeHeader::CONTENT_TYPE, MimeParameter::NAME);
|
||||
}
|
||||
|
||||
$sMailEncodingName = $oHeaders->ValueByName(MimeHeader::CONTENT_TRANSFER_ENCODING);
|
||||
$sMailEncoding = \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName(
|
||||
$oHeaders->ValueByName(MimeHeader::CONTENT_TRANSFER_ENCODING)
|
||||
);
|
||||
|
||||
$sContentType = $oHeaders->ValueByName(MimeHeader::CONTENT_TYPE);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSubject = $oHeaders->ValueByName(MimeHeader::SUBJECT);
|
||||
|
||||
$sFileName = \strlen($sSubject) ? $sSubject : (string) $iIndex;
|
||||
$sFileName .= '.eml';
|
||||
$sFileName = ($oHeaders->ValueByName(MimeHeader::SUBJECT) ?: $iIndex) . '.eml';
|
||||
|
||||
$sContentType = 'message/rfc822';
|
||||
}
|
||||
|
@ -276,17 +273,14 @@ class MailClient
|
|||
// Push in the aFetchCallbacks array and then called by \MailSo\Imap\Traits\ResponseParser::partialResponseLiteralCallbackCallable
|
||||
array(
|
||||
FetchType::BODY_PEEK.'['.$sMimeIndex.']',
|
||||
function ($sParent, $sLiteralAtomUpperCase, $rImapLiteralStream) use ($mCallback, $sMimeIndex, $sMailEncodingName, $sContentType, $sFileName)
|
||||
function ($sParent, $sLiteralAtomUpperCase, $rImapLiteralStream) use ($mCallback, $sMimeIndex, $sMailEncoding, $sContentType, $sFileName)
|
||||
{
|
||||
if (\strlen($sLiteralAtomUpperCase) && \is_resource($rImapLiteralStream) && 'FETCH' === $sParent)
|
||||
{
|
||||
$rMessageMimeIndexStream = \strlen($sMailEncodingName)
|
||||
? \MailSo\Base\StreamWrappers\Binary::CreateStream($rImapLiteralStream,
|
||||
\MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName(
|
||||
$sMailEncodingName, true))
|
||||
: $rImapLiteralStream;
|
||||
|
||||
$mCallback($rMessageMimeIndexStream, $sContentType, $sFileName, $sMimeIndex);
|
||||
$mCallback($sMailEncoding
|
||||
? \MailSo\Base\StreamWrappers\Binary::CreateStream($rImapLiteralStream, $sMailEncoding)
|
||||
: $rImapLiteralStream,
|
||||
$sContentType, $sFileName, $sMimeIndex);
|
||||
}
|
||||
}
|
||||
)), $iIndex, $bIndexIsUid);
|
||||
|
|
Loading…
Reference in a new issue