Exemplo n.º 1
0
 /**
  * @param mixed $mCallback
  * @param string $sFolderName
  * @param int $iIndex
  * @param bool $bIndexIsUid = true,
  * @param string $sMimeIndex = ''
  *
  * @return bool
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function MessageMimeStream($mCallback, $sFolderName, $iIndex, $bIndexIsUid = true, $sMimeIndex = '')
 {
     if (!is_callable($mCallback)) {
         throw new \MailSo\Base\Exceptions\InvalidArgumentException();
     }
     $this->oImapClient->FolderExamine($sFolderName);
     $sFileName = '';
     $sContentType = '';
     $sMailEncodingName = '';
     $sMimeIndex = trim($sMimeIndex);
     $aFetchResponse = $this->oImapClient->Fetch(array(0 === \strlen($sMimeIndex) ? \MailSo\Imap\Enumerations\FetchType::BODY_HEADER_PEEK : \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $sMimeIndex . '.MIME]'), $iIndex, $bIndexIsUid);
     if (0 < \count($aFetchResponse)) {
         $sMime = $aFetchResponse[0]->GetFetchValue(0 === \strlen($sMimeIndex) ? \MailSo\Imap\Enumerations\FetchType::BODY_HEADER : \MailSo\Imap\Enumerations\FetchType::BODY . '[' . $sMimeIndex . '.MIME]');
         if (0 < \strlen($sMime)) {
             $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sMime);
             if (0 < \strlen($sMimeIndex)) {
                 $sFileName = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_DISPOSITION, \MailSo\Mime\Enumerations\Parameter::FILENAME);
                 if (0 === \strlen($sFileName)) {
                     $sFileName = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::NAME);
                 }
                 $sMailEncodingName = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING);
                 $sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
             } else {
                 $sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT);
                 $sFileName = 0 === \strlen($sSubject) ? (string) $iIndex : $sSubject;
                 $sFileName .= '.eml';
                 $sContentType = 'message/rfc822';
             }
         }
     }
     $aFetchResponse = $this->oImapClient->Fetch(array(array(\MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $sMimeIndex . ']', function ($sParent, $sLiteralAtomUpperCase, $rImapLiteralStream) use($mCallback, $sMimeIndex, $sMailEncodingName, $sContentType, $sFileName) {
         if (0 < \strlen($sLiteralAtomUpperCase)) {
             if (is_resource($rImapLiteralStream) && 'FETCH' === $sParent) {
                 $rMessageMimeIndexStream = 0 === \strlen($sMailEncodingName) ? $rImapLiteralStream : \MailSo\Base\StreamWrappers\Binary::CreateStream($rImapLiteralStream, \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName($sMailEncodingName, true));
                 \call_user_func($mCallback, $rMessageMimeIndexStream, $sContentType, $sFileName, $sMimeIndex);
             }
         }
     })), $iIndex, $bIndexIsUid);
     return $aFetchResponse && 1 === \count($aFetchResponse);
 }
Exemplo n.º 2
0
 /**
  * @param array $aAlternativeData
  *
  * @return \MailSo\Mime\Part
  */
 private function createNewMessageAlternativePartBody($aAlternativeData)
 {
     $oAlternativePart = null;
     if (is_array($aAlternativeData) && isset($aAlternativeData[0])) {
         $oAlternativePart = Part::NewInstance();
         $oParameters = ParameterCollection::NewInstance();
         $oParameters->Add(Parameter::NewInstance(\MailSo\Mime\Enumerations\Parameter::CHARSET, \MailSo\Base\Enumerations\Charset::UTF_8));
         if (isset($aAlternativeData[3]) && \is_array($aAlternativeData[3]) && 0 < \count($aAlternativeData[3])) {
             foreach ($aAlternativeData[3] as $sName => $sValue) {
                 $oParameters->Add(Parameter::NewInstance($sName, $sValue));
             }
         }
         $oAlternativePart->Headers->Add(Header::NewInstance(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, $aAlternativeData[0] . '; ' . $oParameters->ToString()));
         $oAlternativePart->Body = null;
         if (isset($aAlternativeData[1])) {
             if (is_resource($aAlternativeData[1])) {
                 $oAlternativePart->Body = $aAlternativeData[1];
             } else {
                 if (is_string($aAlternativeData[1]) && 0 < strlen($aAlternativeData[1])) {
                     $oAlternativePart->Body = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($aAlternativeData[1]);
                 }
             }
         }
         if (isset($aAlternativeData[2]) && 0 < strlen($aAlternativeData[2])) {
             $oAlternativePart->Headers->Add(Header::NewInstance(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, $aAlternativeData[2]));
             if (is_resource($oAlternativePart->Body)) {
                 if (!\MailSo\Base\StreamWrappers\Binary::IsStreamRemembed($oAlternativePart->Body)) {
                     $oAlternativePart->Body = \MailSo\Base\StreamWrappers\Binary::CreateStream($oAlternativePart->Body, \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName($aAlternativeData[2], false));
                     \MailSo\Base\StreamWrappers\Binary::RememberStream($oAlternativePart->Body);
                 }
             }
         }
         if (!is_resource($oAlternativePart->Body)) {
             $oAlternativePart->Body = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString('');
         }
     }
     return $oAlternativePart;
 }