/** * @param string $sFolderName * @param int $iIndex * @param bool $bIndexIsUid = true * @param mixed $oCacher = null * * @return \MailSo\Mail\Message|false * * @throws \MailSo\Base\Exceptions\InvalidArgumentException * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception */ public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = null) { if (!\MailSo\Base\Validator::RangeInt($iIndex, 1)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $this->oImapClient->FolderExamine($sFolderName); $oBodyStructure = null; $oMessage = false; $aTextMimeIndexes = array(); $aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid); if (0 < \count($aFetchResponse)) { $oBodyStructure = $aFetchResponse[0]->GetFetchBodyStructure(); $aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null; if (is_array($aTextParts) && 0 < \count($aTextParts)) { foreach ($aTextParts as $oPart) { $aTextMimeIndexes[] = $oPart->PartID(); } } } $aFetchItems = array(\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::UID, \MailSo\Imap\Enumerations\FetchType::RFC822_SIZE, \MailSo\Imap\Enumerations\FetchType::INTERNALDATE, \MailSo\Imap\Enumerations\FetchType::FLAGS, $this->getEnvelopeOrHeadersRequestString()); if (0 < \count($aTextMimeIndexes)) { foreach ($aTextMimeIndexes as $sTextMimeIndex) { $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $sTextMimeIndex . ']'; } } if (!$oBodyStructure) { $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE; } $aFetchResponse = $this->oImapClient->Fetch($aFetchItems, $iIndex, $bIndexIsUid); if (0 < \count($aFetchResponse)) { $oMessage = \MailSo\Mail\Message::NewFetchResponseInstance($sFolderName, $aFetchResponse[0], $oBodyStructure); } return $oMessage; }
/** * @param string $sFolderName * @param int $iIndex * @param bool $bIndexIsUid = true * @param \MailSo\Cache\CacheClient $oCacher = null * @param int $iBodyTextLimit = null * * @return \MailSo\Mail\Message|false * * @throws \MailSo\Base\Exceptions\InvalidArgumentException * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception */ public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = null, $iBodyTextLimit = null) { if (!\MailSo\Base\Validator::RangeInt($iIndex, 1)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $this->oImapClient->FolderSelect($sFolderName); $oBodyStructure = null; $oMessage = false; $aBodyPeekMimeIndexes = array(); $aSignatureMimeIndexes = array(); $aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid); if (0 < \count($aFetchResponse) && isset($aFetchResponse[0])) { $oBodyStructure = $aFetchResponse[0]->GetFetchBodyStructure(); if ($oBodyStructure) { $aTextParts = $oBodyStructure->SearchHtmlOrPlainParts(); if (is_array($aTextParts) && 0 < \count($aTextParts)) { foreach ($aTextParts as $oPart) { $aBodyPeekMimeIndexes[] = array($oPart->PartID(), $oPart->Size()); } } $aSignatureParts = $oBodyStructure->SearchByContentType('application/pgp-signature'); if (is_array($aSignatureParts) && 0 < \count($aSignatureParts)) { foreach ($aSignatureParts as $oPart) { $aSignatureMimeIndexes[] = $oPart->PartID(); } } } } $aFetchItems = array(\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::UID, \MailSo\Imap\Enumerations\FetchType::RFC822_SIZE, \MailSo\Imap\Enumerations\FetchType::INTERNALDATE, \MailSo\Imap\Enumerations\FetchType::FLAGS, $this->getEnvelopeOrHeadersRequestString()); if (0 < \count($aBodyPeekMimeIndexes)) { 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 . ']'; } } if (!$oBodyStructure) { $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE; } $aFetchResponse = $this->oImapClient->Fetch($aFetchItems, $iIndex, $bIndexIsUid); if (0 < \count($aFetchResponse)) { $oMessage = \MailSo\Mail\Message::NewFetchResponseInstance($sFolderName, $aFetchResponse[0], $oBodyStructure); } return $oMessage; }