예제 #1
0
 /**
  * @param array $aInput
  */
 public static function ClearArrayUtf8Values(&$aInput)
 {
     if (\is_array($aInput)) {
         foreach ($aInput as $mKey => $mItem) {
             if (\is_string($mItem)) {
                 $aInput[$mKey] = \MailSo\Base\Utils::Utf8Clear($mItem);
             } else {
                 if (\is_array($mItem)) {
                     \MailSo\Base\Utils::ClearArrayUtf8Values($mItem);
                     $aInput[$mKey] = $mItem;
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * @param string $sFileName
  * @param string $sContentType
  * @param string $sMimeIndex = ''
  *
  * @return string
  */
 public function clearFileName($sFileName, $sContentType, $sMimeIndex = '')
 {
     $sFileName = 0 === strlen($sFileName) ? preg_replace('/[^a-zA-Z0-9]/', '.', (empty($sMimeIndex) ? '' : $sMimeIndex . '.') . $sContentType) : $sFileName;
     $sClearedFileName = preg_replace('/[\\s]+/', ' ', preg_replace('/[\\.]+/', '.', $sFileName));
     $sExt = \MailSo\Base\Utils::GetFileExtension($sClearedFileName);
     $iSize = 100;
     if ($iSize < strlen($sClearedFileName) - strlen($sExt)) {
         $sClearedFileName = substr($sClearedFileName, 0, $iSize) . (empty($sExt) ? '' : '.' . $sExt);
     }
     return \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::Utf8Clear($sClearedFileName));
 }
예제 #3
0
 /**
  * @param array $aBodyStructure
  * @param string $sPartID = ''
  *
  * @return \MailSo\Imap\BodyStructure
  */
 public static function NewInstance(array $aBodyStructure, $sPartID = '')
 {
     if (!\is_array($aBodyStructure) || 2 > \count($aBodyStructure)) {
         return null;
     } else {
         $sBodyMainType = null;
         if (\is_string($aBodyStructure[0]) && 'NIL' !== $aBodyStructure[0]) {
             $sBodyMainType = $aBodyStructure[0];
         }
         $sBodySubType = null;
         $sContentType = '';
         $aSubParts = null;
         $aBodyParams = array();
         $sName = null;
         $sCharset = null;
         $sContentID = null;
         $sDescription = null;
         $sMailEncodingName = null;
         $iSize = 0;
         $iTextLineCount = 0;
         // valid for rfc822/message and text parts
         $iExtraItemPos = 0;
         // list index of items which have no well-established position (such as 0, 1, 5, etc).
         if (null === $sBodyMainType) {
             // Process multipart body structure
             if (!\is_array($aBodyStructure[0])) {
                 return null;
             } else {
                 $sBodyMainType = 'multipart';
                 $sSubPartIDPrefix = '';
                 if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) {
                     // This multi-part is root part of message.
                     $sSubPartIDPrefix = $sPartID;
                     $sPartID .= 'TEXT';
                 } else {
                     if (0 < \strlen($sPartID)) {
                         // This multi-part is a part of another multi-part.
                         $sSubPartIDPrefix = $sPartID . '.';
                     }
                 }
                 $aSubParts = array();
                 $iIndex = 1;
                 while ($iExtraItemPos < \count($aBodyStructure) && \is_array($aBodyStructure[$iExtraItemPos])) {
                     $oPart = self::NewInstance($aBodyStructure[$iExtraItemPos], $sSubPartIDPrefix . $iIndex);
                     if (null === $oPart) {
                         return null;
                     } else {
                         // For multipart, we have no charset info in the part itself. Thus,
                         // obtain charset from nested parts.
                         if ($sCharset == null) {
                             $sCharset = $oPart->Charset();
                         }
                         $aSubParts[] = $oPart;
                         $iExtraItemPos++;
                         $iIndex++;
                     }
                 }
             }
             if ($iExtraItemPos < \count($aBodyStructure)) {
                 if (!\is_string($aBodyStructure[$iExtraItemPos]) || 'NIL' === $aBodyStructure[$iExtraItemPos]) {
                     return null;
                 }
                 $sBodySubType = \strtolower($aBodyStructure[$iExtraItemPos]);
                 $iExtraItemPos++;
             }
             if ($iExtraItemPos < \count($aBodyStructure)) {
                 $sBodyParamList = $aBodyStructure[$iExtraItemPos];
                 if (\is_array($sBodyParamList)) {
                     $aBodyParams = self::getKeyValueListFromArrayList($sBodyParamList);
                 }
             }
             $iExtraItemPos++;
         } else {
             // Process simple (singlepart) body structure
             if (7 > \count($aBodyStructure)) {
                 return null;
             }
             $sBodyMainType = \strtolower($sBodyMainType);
             if (!\is_string($aBodyStructure[1]) || 'NIL' === $aBodyStructure[1]) {
                 return null;
             }
             $sBodySubType = \strtolower($aBodyStructure[1]);
             $aBodyParamList = $aBodyStructure[2];
             if (\is_array($aBodyParamList)) {
                 $aBodyParams = self::getKeyValueListFromArrayList($aBodyParamList);
                 if (isset($aBodyParams['charset'])) {
                     $sCharset = $aBodyParams['charset'];
                 }
                 if (\is_array($aBodyParams)) {
                     $sName = self::decodeAttrParamenter($aBodyParams, 'name', $sContentType);
                 }
             }
             if (null !== $aBodyStructure[3] && 'NIL' !== $aBodyStructure[3]) {
                 if (!\is_string($aBodyStructure[3])) {
                     return null;
                 }
                 $sContentID = $aBodyStructure[3];
             }
             if (null !== $aBodyStructure[4] && 'NIL' !== $aBodyStructure[4]) {
                 if (!\is_string($aBodyStructure[4])) {
                     return null;
                 }
                 $sDescription = $aBodyStructure[4];
             }
             if (null !== $aBodyStructure[5] && 'NIL' !== $aBodyStructure[5]) {
                 if (!\is_string($aBodyStructure[5])) {
                     return null;
                 }
                 $sMailEncodingName = $aBodyStructure[5];
             }
             if (\is_numeric($aBodyStructure[6])) {
                 $iSize = (int) $aBodyStructure[6];
             } else {
                 $iSize = -1;
             }
             if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) {
                 // This is the only sub-part of the message (otherwise, it would be
                 // one of sub-parts of a multi-part, and partID would already be fully set up).
                 $sPartID .= '1';
             }
             $iExtraItemPos = 7;
             if ('text' === $sBodyMainType) {
                 if ($iExtraItemPos < \count($aBodyStructure)) {
                     if (\is_numeric($aBodyStructure[$iExtraItemPos])) {
                         $iTextLineCount = (int) $aBodyStructure[$iExtraItemPos];
                     } else {
                         $iTextLineCount = -1;
                     }
                 } else {
                     $iTextLineCount = -1;
                 }
                 $iExtraItemPos++;
             } else {
                 if ('message' === $sBodyMainType && 'rfc822' === $sBodySubType) {
                     if ($iExtraItemPos + 2 < \count($aBodyStructure)) {
                         if (\is_numeric($aBodyStructure[$iExtraItemPos + 2])) {
                             $iTextLineCount = (int) $aBodyStructure[$iExtraItemPos + 2];
                         } else {
                             $iTextLineCount = -1;
                         }
                     } else {
                         $iTextLineCount = -1;
                     }
                     $iExtraItemPos += 3;
                 }
             }
             $iExtraItemPos++;
             // skip MD5 digest of the body because most mail servers leave it NIL anyway
         }
         $sContentType = $sBodyMainType . '/' . $sBodySubType;
         $sDisposition = null;
         $aDispositionParams = null;
         $sFileName = null;
         if ($iExtraItemPos < \count($aBodyStructure)) {
             $aDispList = $aBodyStructure[$iExtraItemPos];
             if (\is_array($aDispList) && 1 < \count($aDispList)) {
                 if (null !== $aDispList[0]) {
                     if (\is_string($aDispList[0]) && 'NIL' !== $aDispList[0]) {
                         $sDisposition = $aDispList[0];
                     } else {
                         return null;
                     }
                 }
             }
             $aDispParamList = $aDispList[1];
             if (\is_array($aDispParamList)) {
                 $aDispositionParams = self::getKeyValueListFromArrayList($aDispParamList);
                 if (\is_array($aDispositionParams)) {
                     $sFileName = self::decodeAttrParamenter($aDispositionParams, 'filename', $sCharset);
                 }
             }
         }
         $iExtraItemPos++;
         $sLanguage = null;
         if ($iExtraItemPos < count($aBodyStructure)) {
             if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos]) {
                 if (\is_array($aBodyStructure[$iExtraItemPos])) {
                     $sLanguage = \implode(',', $aBodyStructure[$iExtraItemPos]);
                 } else {
                     if (\is_string($aBodyStructure[$iExtraItemPos])) {
                         $sLanguage = $aBodyStructure[$iExtraItemPos];
                     }
                 }
             }
             $iExtraItemPos++;
         }
         $sLocation = null;
         if ($iExtraItemPos < \count($aBodyStructure)) {
             if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos]) {
                 if (\is_string($aBodyStructure[$iExtraItemPos])) {
                     $sLocation = $aBodyStructure[$iExtraItemPos];
                 }
             }
             $iExtraItemPos++;
         }
         return new self($sContentType, $sCharset, $aBodyParams, $sContentID, $sDescription, $sMailEncodingName, $sDisposition, $aDispositionParams, \MailSo\Base\Utils::Utf8Clear(null === $sFileName || 0 === \strlen($sFileName) ? $sName : $sFileName), $sLanguage, $sLocation, $iSize, $iTextLineCount, $sPartID, $aSubParts);
     }
 }
예제 #4
0
 /**
  * @param \CAccount $oAccount
  * @param mixed $mResponse
  * @param string $sParent
  * @param array $aParameters = array()
  *
  * @return mixed
  */
 protected function responseObject($oAccount, $mResponse, $sParent, $aParameters = array())
 {
     $mResult = $mResponse;
     if (is_object($mResponse)) {
         $sClassName = get_class($mResponse);
         if ('CApiMailMessage' === $sClassName) {
             $iTrimmedLimit = \CApi::GetConf('labs.message-body-size-limit', 0);
             $oAttachments = $mResponse->getAttachments();
             $iInternalTimeStampInUTC = $mResponse->getInternalTimeStamp();
             $iReceivedOrDateTimeStampInUTC = $mResponse->getReceivedOrDateTimeStamp();
             $aFlags = $mResponse->getFlagsLowerCase();
             $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Folder' => $mResponse->getFolder(), 'Uid' => $mResponse->getUid(), 'Subject' => $mResponse->getSubject(), 'MessageId' => $mResponse->getMessageId(), 'Size' => $mResponse->getSize(), 'TextSize' => $mResponse->getTextSize(), 'InternalTimeStampInUTC' => $iInternalTimeStampInUTC, 'ReceivedOrDateTimeStampInUTC' => $iReceivedOrDateTimeStampInUTC, 'TimeStampInUTC' => \CApi::GetConf('labs.use-date-from-headers', false) && 0 < $iReceivedOrDateTimeStampInUTC ? $iReceivedOrDateTimeStampInUTC : $iInternalTimeStampInUTC, 'From' => $this->responseObject($oAccount, $mResponse->getFrom(), $sParent, $aParameters), 'To' => $this->responseObject($oAccount, $mResponse->getTo(), $sParent, $aParameters), 'Cc' => $this->responseObject($oAccount, $mResponse->getCc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($oAccount, $mResponse->getBcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($oAccount, $mResponse->getSender(), $sParent, $aParameters), 'ReplyTo' => $this->responseObject($oAccount, $mResponse->getReplyTo(), $sParent, $aParameters), 'IsSeen' => in_array('\\seen', $aFlags), 'IsFlagged' => in_array('\\flagged', $aFlags), 'IsAnswered' => in_array('\\answered', $aFlags), 'IsForwarded' => false, 'HasAttachments' => $oAttachments && $oAttachments->hasNotInlineAttachments(), 'HasVcardAttachment' => $oAttachments && $oAttachments->hasVcardAttachment(), 'HasIcalAttachment' => $oAttachments && $oAttachments->hasIcalAttachment(), 'Priority' => $mResponse->getPriority(), 'DraftInfo' => $mResponse->getDraftInfo(), 'Sensitivity' => $mResponse->getSensitivity()));
             $mResult['TrimmedTextSize'] = $mResult['TextSize'];
             if (0 < $iTrimmedLimit && $mResult['TrimmedTextSize'] > $iTrimmedLimit) {
                 $mResult['TrimmedTextSize'] = $iTrimmedLimit;
             }
             $sLowerForwarded = strtolower(\CApi::GetConf('webmail.forwarded-flag-name', ''));
             if (!empty($sLowerForwarded)) {
                 $mResult['IsForwarded'] = in_array($sLowerForwarded, $aFlags);
             }
             $mResult['Hash'] = \CApi::EncodeKeyValues(array('AccountID' => $oAccount ? $oAccount->IdAccount : 0, 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => $mResult['Subject'] . '.eml'));
             if ('MessageGet' === $sParent || 'MessagesGetBodies' === $sParent) {
                 $mResult['Headers'] = \MailSo\Base\Utils::Utf8Clear($mResponse->getHeaders());
                 $mResult['InReplyTo'] = $mResponse->getInReplyTo();
                 $mResult['References'] = $mResponse->getReferences();
                 $mResult['ReadingConfirmation'] = $mResponse->getReadingConfirmation();
                 if (!empty($mResult['ReadingConfirmation']) && in_array('$readconfirm', $aFlags)) {
                     $mResult['ReadingConfirmation'] = '';
                 }
                 $bHasExternals = false;
                 $aFoundedCIDs = array();
                 $sPlain = '';
                 $sHtml = trim($mResponse->getHtml());
                 if (0 === strlen($sHtml)) {
                     $sPlain = $mResponse->getPlain();
                 }
                 $aContentLocationUrls = array();
                 $aFoundedContentLocationUrls = array();
                 if ($oAttachments && 0 < $oAttachments->Count()) {
                     $aList =& $oAttachments->GetAsArray();
                     foreach ($aList as $oAttachment) {
                         if ($oAttachment) {
                             $sContentLocation = $oAttachment->getContentLocation();
                             if ($sContentLocation && 0 < \strlen($sContentLocation)) {
                                 $aContentLocationUrls[] = $oAttachment->getContentLocation();
                             }
                         }
                     }
                 }
                 $iTextSizeLimit = 500000;
                 if ($iTextSizeLimit < \strlen($sHtml)) {
                     $iSpacePost = \strpos($sHtml, ' ', $iTextSizeLimit);
                     $sHtml = \substr($sHtml, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit);
                 }
                 if ($iTextSizeLimit < \strlen($sPlain)) {
                     $iSpacePost = \strpos($sPlain, ' ', $iTextSizeLimit);
                     $sPlain = \substr($sPlain, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit);
                 }
                 if (0 < \strlen($sHtml) && \CApi::GetConf('labs.webmail.display-inline-css', false)) {
                     include_once PSEVEN_APP_ROOT_PATH . 'libraries/other/CssToInlineStyles.php';
                     $oCssToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml);
                     $oCssToInlineStyles->setEncoding('utf-8');
                     $oCssToInlineStyles->setUseInlineStylesBlock(true);
                     $mResult['Html'] = \MailSo\Base\HtmlUtils::ClearHtml($oCssToInlineStyles->convert(), $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true);
                 } else {
                     $mResult['Html'] = 0 === strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true);
                 }
                 $mResult['Trimmed'] = false;
                 $mResult['Plain'] = 0 === strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
                 $mResult['PlainRaw'] = \trim($sPlain);
                 $mResult['Rtl'] = 0 < \strlen($mResult['Plain']) ? \MailSo\Base\Utils::IsRTL($mResult['Plain']) : false;
                 if (0 < $iTrimmedLimit && 'Messages' === $sParent) {
                     if ($iTrimmedLimit < strlen($mResult['Plain'])) {
                         $iPos = strpos($mResult['Plain'], ' ', $iTrimmedLimit);
                         if (false !== $iPos && $iTrimmedLimit <= $iPos) {
                             $mResult['Plain'] = substr($mResult['Plain'], 0, $iPos);
                             $mResult['Trimmed'] = true;
                         }
                     }
                     if ($iTrimmedLimit < strlen($mResult['Html'])) {
                         $iPos = strpos($mResult['Html'], ' <', $iTrimmedLimit);
                         if (false !== $iPos && $iTrimmedLimit <= $iPos) {
                             $mResult['Html'] = substr($mResult['Html'], 0, $iPos) . '<!-- cutted -->';
                             $mResult['Trimmed'] = true;
                         }
                     }
                 }
                 $mResult['ICAL'] = $this->responseObject($oAccount, $mResponse->getExtend('ICAL'), $sParent, $aParameters);
                 $mResult['VCARD'] = $this->responseObject($oAccount, $mResponse->getExtend('VCARD'), $sParent, $aParameters);
                 $mResult['Safety'] = $mResponse->getSafety();
                 $mResult['HasExternals'] = $bHasExternals;
                 $mResult['FoundedCIDs'] = $aFoundedCIDs;
                 $mResult['FoundedContentLocationUrls'] = $aFoundedContentLocationUrls;
                 $mResult['Attachments'] = $this->responseObject($oAccount, $oAttachments, $sParent, array_merge($aParameters, array('FoundedCIDs' => $aFoundedCIDs, 'FoundedContentLocationUrls' => $aFoundedContentLocationUrls)));
                 //					$mResult['Html'] = \MailSo\Base\Utils::Utf8Clear($mResult['Html']);
                 //					$mResult['Plain'] = \MailSo\Base\Utils::Utf8Clear($mResult['Plain']);
             } else {
                 $mResult['@Object'] = 'Object/MessageListItem';
                 $mResult['Threads'] = $mResponse->getThreads();
             }
             $mResult['Custom'] = $this->responseObject($oAccount, $mResponse->getCustomList(), $sParent, $aParameters);
             $mResult['Subject'] = \MailSo\Base\Utils::Utf8Clear($mResult['Subject']);
         } else {
             if ('CApiMailIcs' === $sClassName) {
                 $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uid' => $mResponse->Uid, 'Sequence' => $mResponse->Sequence, 'Attendee' => $mResponse->Attendee, 'File' => $mResponse->File, 'Type' => $mResponse->Type, 'Location' => $mResponse->Location, 'Description' => \MailSo\Base\LinkFinder::NewInstance()->Text($mResponse->Description)->UseDefaultWrappers(true)->CompileText(), 'When' => $mResponse->When, 'CalendarId' => $mResponse->CalendarId));
             } else {
                 if ('CApiMailVcard' === $sClassName) {
                     $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uid' => $mResponse->Uid, 'File' => $mResponse->File, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Exists' => $mResponse->Exists));
                 } else {
                     if ('CFilter' === $sClassName) {
                         $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Enable' => $mResponse->Enable, 'Field' => $mResponse->Field, 'Filter' => $mResponse->Filter, 'Condition' => $mResponse->Condition, 'Action' => $mResponse->Action, 'FolderFullName' => $mResponse->FolderFullName));
                     } else {
                         if ('CHelpdeskThread' === $sClassName) {
                             $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'ThreadHash' => $mResponse->StrHelpdeskThreadHash, 'IdOwner' => $mResponse->IdOwner, 'Owner' => $mResponse->Owner, 'Type' => $mResponse->Type, 'Subject' => $mResponse->Subject, 'IsRead' => $mResponse->IsRead, 'IsArchived' => $mResponse->IsArchived, 'ItsMe' => $mResponse->ItsMe, 'HasAttachments' => $mResponse->HasAttachments, 'PostCount' => $mResponse->PostCount, 'Created' => $mResponse->Created, 'Updated' => $mResponse->Updated));
                         } else {
                             if ('CHelpdeskPost' === $sClassName) {
                                 $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskPost' => $mResponse->IdHelpdeskPost, 'IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'IdOwner' => $mResponse->IdOwner, 'Owner' => $mResponse->Owner, 'Attachments' => $this->responseObject($oAccount, $mResponse->Attachments, $sParent), 'IsThreadOwner' => $mResponse->IsThreadOwner, 'ItsMe' => $mResponse->ItsMe, 'Type' => $mResponse->Type, 'SystemType' => $mResponse->SystemType, 'Text' => \MailSo\Base\HtmlUtils::ConvertPlainToHtml($mResponse->Text), 'Created' => $mResponse->Created));
                             } else {
                                 if ('CHelpdeskAttachment' === $sClassName) {
                                     $iThumbnailLimit = 1024 * 1024 * 2;
                                     // 2MB
                                     /* @var $mResponse CHelpdeskAttachment */
                                     $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdHelpdeskAttachment' => $mResponse->IdHelpdeskAttachment, 'IdHelpdeskPost' => $mResponse->IdHelpdeskPost, 'IdHelpdeskThread' => $mResponse->IdHelpdeskThread, 'SizeInBytes' => $mResponse->SizeInBytes, 'FileName' => $mResponse->FileName, 'MimeType' => \MailSo\Base\Utils::MimeContentType($mResponse->FileName), 'Thumb' => \CApi::GetConf('labs.allow-thumbnail', true) && $mResponse->SizeInBytes < $iThumbnailLimit && \api_Utils::IsGDImageMimeTypeSuppoted(\MailSo\Base\Utils::MimeContentType($mResponse->FileName), $mResponse->FileName), 'Hash' => $mResponse->Hash, 'Content' => $mResponse->Content, 'Created' => $mResponse->Created));
                                 } else {
                                     if ('CFetcher' === $sClassName) {
                                         /* @var $mResponse \CFetcher */
                                         $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdFetcher' => $mResponse->IdFetcher, 'IdAccount' => $mResponse->IdAccount, 'IsEnabled' => $mResponse->IsEnabled, 'IsLocked' => $mResponse->IsLocked, 'Folder' => $mResponse->Folder, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Signature' => $mResponse->Signature, 'SignatureOptions' => $mResponse->SignatureOptions, 'LeaveMessagesOnServer' => $mResponse->LeaveMessagesOnServer, 'IncomingMailServer' => $mResponse->IncomingMailServer, 'IncomingMailPort' => $mResponse->IncomingMailPort, 'IncomingMailLogin' => $mResponse->IncomingMailLogin, 'IsOutgoingEnabled' => $mResponse->IsOutgoingEnabled, 'OutgoingMailServer' => $mResponse->OutgoingMailServer, 'OutgoingMailPort' => $mResponse->OutgoingMailPort, 'OutgoingMailAuth' => $mResponse->OutgoingMailAuth, 'IncomingMailSsl' => $mResponse->IncomingMailSecurity === \MailSo\Net\Enumerations\ConnectionSecurityType::SSL, 'OutgoingMailSsl' => $mResponse->OutgoingMailSecurity === \MailSo\Net\Enumerations\ConnectionSecurityType::SSL));
                                     } else {
                                         if ('CApiMailFolder' === $sClassName) {
                                             $aExtended = null;
                                             $mStatus = $mResponse->getStatus();
                                             if (is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'])) {
                                                 $aExtended = array('MessageCount' => (int) $mStatus['MESSAGES'], 'MessageUnseenCount' => (int) $mStatus['UNSEEN'], 'UidNext' => (string) $mStatus['UIDNEXT'], 'Hash' => \api_Utils::GenerateFolderHash($mResponse->getRawFullName(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT']));
                                             }
                                             $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Type' => $mResponse->getType(), 'Name' => $mResponse->getName(), 'FullName' => $mResponse->getFullName(), 'FullNameRaw' => $mResponse->getRawFullName(), 'FullNameHash' => md5($mResponse->getRawFullName()), 'Delimiter' => $mResponse->getDelimiter(), 'IsSubscribed' => $oAccount->isExtensionEnabled(\CAccount::IgnoreSubscribeStatus) ? true : $mResponse->isSubscribed(), 'IsSelectable' => $mResponse->isSelectable(), 'Exists' => $mResponse->exists(), 'Extended' => $aExtended, 'SubFolders' => $this->responseObject($oAccount, $mResponse->getSubFolders(), $sParent, $aParameters)));
                                         } else {
                                             if ('CApiMailAttachment' === $sClassName) {
                                                 $mFoundedCIDs = isset($aParameters['FoundedCIDs']) && is_array($aParameters['FoundedCIDs']) ? $aParameters['FoundedCIDs'] : null;
                                                 $mFoundedContentLocationUrls = isset($aParameters['FoundedContentLocationUrls']) && \is_array($aParameters['FoundedContentLocationUrls']) && 0 < \count($aParameters['FoundedContentLocationUrls']) ? $aParameters['FoundedContentLocationUrls'] : null;
                                                 if ($mFoundedCIDs || $mFoundedContentLocationUrls) {
                                                     $aFoundedCIDs = \array_merge($mFoundedCIDs ? $mFoundedCIDs : array(), $mFoundedContentLocationUrls ? $mFoundedContentLocationUrls : array());
                                                     $aFoundedCIDs = 0 < \count($mFoundedCIDs) ? $mFoundedCIDs : null;
                                                 }
                                                 $sMimeType = strtolower(trim($mResponse->getMimeType()));
                                                 $sMimeIndex = strtolower(trim($mResponse->getMimeIndex()));
                                                 $sContentTransferEncoding = strtolower(trim($mResponse->getEncoding()));
                                                 $sFileName = $mResponse->getFileName(true);
                                                 $iEstimatedSize = $mResponse->getEstimatedSize();
                                                 $iThumbnailLimit = 1024 * 1024 * 2;
                                                 // 2MB //TODO
                                                 if (in_array($sMimeType, array('application/octet-stream'))) {
                                                     $sMimeType = \MailSo\Base\Utils::MimeContentType($sFileName);
                                                 }
                                                 $sCid = \trim(\trim($mResponse->getCid()), '<>');
                                                 $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('FileName' => $sFileName, 'MimeType' => $sMimeType, 'MimePartIndex' => 'message/rfc822' === $sMimeType && ('base64' === $sContentTransferEncoding || 'quoted-printable' === $sContentTransferEncoding) ? '' : $sMimeIndex, 'EstimatedSize' => $iEstimatedSize, 'CID' => $sCid, 'ContentLocation' => $mResponse->getContentLocation(), 'Thumb' => \CApi::GetConf('labs.allow-thumbnail', true) && $iEstimatedSize < $iThumbnailLimit && \api_Utils::IsGDImageMimeTypeSuppoted($sMimeType, $sFileName), 'Expand' => \CApi::isExpandMimeTypeSupported($sMimeType, $sFileName), 'Iframed' => \CApi::isIframedMimeTypeSupported($sMimeType, $sFileName), 'Content' => $mResponse->getContent(), 'IsInline' => $mResponse->isInline(), 'IsLinked' => !empty($sCid) && $mFoundedCIDs && \in_array($sCid, $mFoundedCIDs) || $mFoundedContentLocationUrls && \in_array(\trim($mResponse->getContentLocation()), $mFoundedContentLocationUrls)));
                                                 $mResult['Hash'] = \CApi::EncodeKeyValues(array('Iframed' => $mResult['Iframed'], 'AccountID' => $oAccount ? $oAccount->IdAccount : 0, 'Folder' => $mResponse->getFolder(), 'Uid' => $mResponse->getUid(), 'MimeIndex' => $sMimeIndex, 'MimeType' => $sMimeType, 'FileName' => $mResponse->getFileName(true)));
                                             } else {
                                                 if ('MailSo\\Mime\\Email' === $sClassName) {
                                                     $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('DisplayName' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()), 'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail())));
                                                 } else {
                                                     if ('CApiMailMessageCollection' === $sClassName) {
                                                         $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Uids' => $mResponse->Uids, 'UidNext' => $mResponse->UidNext, 'FolderHash' => $mResponse->FolderHash, 'MessageCount' => $mResponse->MessageCount, 'MessageUnseenCount' => $mResponse->MessageUnseenCount, 'MessageResultCount' => $mResponse->MessageResultCount, 'FolderName' => $mResponse->FolderName, 'Offset' => $mResponse->Offset, 'Limit' => $mResponse->Limit, 'Search' => $mResponse->Search, 'Filters' => $mResponse->Filters, 'New' => $mResponse->New));
                                                     } else {
                                                         if ('CIdentity' === $sClassName) {
                                                             $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdIdentity' => $mResponse->IdIdentity, 'IdAccount' => $mResponse->IdAccount, 'Default' => $mResponse->Default, 'Enabled' => $mResponse->Enabled, 'Email' => $mResponse->Email, 'FriendlyName' => $mResponse->FriendlyName, 'UseSignature' => $mResponse->UseSignature, 'Signature' => $mResponse->Signature));
                                                         } else {
                                                             if ('CApiMailFolderCollection' === $sClassName) {
                                                                 $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Namespace' => $mResponse->GetNamespace()));
                                                             } else {
                                                                 if ('CContactListItem' === $sClassName) {
                                                                     $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $oAccount->IdUser, 'Id' => $mResponse->Id, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Emails' => $mResponse->Emails, 'Phones' => $mResponse->Phones, 'UseFriendlyName' => $mResponse->UseFriendlyName, 'IsGroup' => $mResponse->IsGroup, 'IsOrganization' => $mResponse->IsOrganization, 'ReadOnly' => $mResponse->ReadOnly, 'ItsMe' => $mResponse->ItsMe, 'Global' => $mResponse->Global, 'ForSharedToAll' => $mResponse->ForSharedToAll, 'SharedToAll' => $mResponse->SharedToAll, 'Frequency' => $mResponse->Frequency, 'AgeScore' => $mResponse->AgeScore));
                                                                 } else {
                                                                     if ('CContact' === $sClassName) {
                                                                         $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $mResponse->IdUser, 'IdContact' => $mResponse->IdContact, 'IdContactStr' => $mResponse->IdContactStr, 'Global' => $mResponse->Global, 'ItsMe' => $mResponse->ItsMe, 'PrimaryEmail' => $mResponse->PrimaryEmail, 'UseFriendlyName' => $mResponse->UseFriendlyName, 'GroupsIds' => $mResponse->GroupsIds, 'FullName' => $mResponse->FullName, 'Title' => $mResponse->Title, 'FirstName' => $mResponse->FirstName, 'LastName' => $mResponse->LastName, 'NickName' => $mResponse->NickName, 'Skype' => $mResponse->Skype, 'Facebook' => $mResponse->Facebook, 'HomeEmail' => $mResponse->HomeEmail, 'HomeStreet' => $mResponse->HomeStreet, 'HomeCity' => $mResponse->HomeCity, 'HomeState' => $mResponse->HomeState, 'HomeZip' => $mResponse->HomeZip, 'HomeCountry' => $mResponse->HomeCountry, 'HomePhone' => $mResponse->HomePhone, 'HomeFax' => $mResponse->HomeFax, 'HomeMobile' => $mResponse->HomeMobile, 'HomeWeb' => $mResponse->HomeWeb, 'BusinessEmail' => $mResponse->BusinessEmail, 'BusinessCompany' => $mResponse->BusinessCompany, 'BusinessStreet' => $mResponse->BusinessStreet, 'BusinessCity' => $mResponse->BusinessCity, 'BusinessState' => $mResponse->BusinessState, 'BusinessZip' => $mResponse->BusinessZip, 'BusinessCountry' => $mResponse->BusinessCountry, 'BusinessJobTitle' => $mResponse->BusinessJobTitle, 'BusinessDepartment' => $mResponse->BusinessDepartment, 'BusinessOffice' => $mResponse->BusinessOffice, 'BusinessPhone' => $mResponse->BusinessPhone, 'BusinessMobile' => $mResponse->BusinessMobile, 'BusinessFax' => $mResponse->BusinessFax, 'BusinessWeb' => $mResponse->BusinessWeb, 'OtherEmail' => $mResponse->OtherEmail, 'Notes' => $mResponse->Notes, 'BirthdayDay' => $mResponse->BirthdayDay, 'BirthdayMonth' => $mResponse->BirthdayMonth, 'BirthdayYear' => $mResponse->BirthdayYear, 'ReadOnly' => $mResponse->ReadOnly, 'ETag' => $mResponse->ETag, 'SharedToAll' => $mResponse->SharedToAll));
                                                                     } else {
                                                                         if ('CGroup' === $sClassName) {
                                                                             $aContacts = $this->ApiContacts()->getContactItems($mResponse->IdUser, \EContactSortField::Name, \ESortOrder::ASC, 0, 299, '', '', $mResponse->IdGroup);
                                                                             $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('IdUser' => $mResponse->IdUser, 'IdGroup' => $mResponse->IdGroup, 'IdGroupStr' => $mResponse->IdGroupStr, 'Name' => $mResponse->Name, 'IsOrganization' => $mResponse->IsOrganization, 'Email' => $mResponse->Email, 'Company' => $mResponse->Company, 'Street' => $mResponse->Street, 'City' => $mResponse->City, 'State' => $mResponse->City, 'Zip' => $mResponse->Zip, 'Country' => $mResponse->Country, 'Phone' => $mResponse->Phone, 'Fax' => $mResponse->Fax, 'Web' => $mResponse->Web, 'Contacts' => $this->responseObject($oAccount, $aContacts, $sParent, $aParameters)));
                                                                         } else {
                                                                             if ($mResponse instanceof \MailSo\Base\Collection) {
                                                                                 $aCollection = $mResponse->GetAsArray();
                                                                                 if (150 < \count($aCollection) && $mResponse instanceof \MailSo\Mime\EmailCollection) {
                                                                                     $aCollection = \array_slice($aCollection, 0, 150);
                                                                                 }
                                                                                 $mResult = $this->responseObject($oAccount, $aCollection, $sParent, $aParameters);
                                                                                 unset($aCollection);
                                                                             } else {
                                                                                 if ('CSocial' === $sClassName) {
                                                                                     $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), $mResponse->toArray());
                                                                                 } else {
                                                                                     if ('CFileStorageItem' === $sClassName) {
                                                                                         $mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Id' => $mResponse->Id, 'Type' => $mResponse->TypeStr, 'Path' => $mResponse->Path, 'FullPath' => $mResponse->FullPath, 'Name' => $mResponse->Name, 'Size' => $mResponse->Size, 'IsFolder' => $mResponse->IsFolder, 'IsLink' => $mResponse->IsLink, 'LinkType' => $mResponse->LinkType, 'LinkUrl' => $mResponse->LinkUrl, 'LastModified' => $mResponse->LastModified, 'ContentType' => $mResponse->ContentType, 'Iframed' => $mResponse->Iframed, 'Thumb' => $mResponse->Thumb, 'ThumbnailLink' => $mResponse->ThumbnailLink, 'OembedHtml' => $mResponse->OembedHtml, 'Hash' => $mResponse->Hash, 'Shared' => $mResponse->Shared, 'Owner' => $mResponse->Owner, 'Content' => $mResponse->Content, 'IsExternal' => $mResponse->IsExternal));
                                                                                     } else {
                                                                                         $mResult = '[' . $sClassName . ']';
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         if (is_array($mResponse)) {
             foreach ($mResponse as $iKey => $oItem) {
                 $mResponse[$iKey] = $this->responseObject($oAccount, $oItem, $sParent, $aParameters);
             }
             $mResult = $mResponse;
         }
     }
     unset($mResponse);
     return $mResult;
 }
예제 #5
0
 /**
  * @param mixed $mResponse
  * @param string $sParent
  * @param array $aParameters = array()
  *
  * @return mixed
  */
 protected function responseObject($mResponse, $sParent = '', $aParameters = array())
 {
     $mResult = $mResponse;
     if (\is_object($mResponse)) {
         $bHook = true;
         $self = $this;
         $sClassName = \get_class($mResponse);
         $bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON');
         $bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS);
         $oAccountCache = null;
         $fGetAccount = function () use($self, &$oAccountCache) {
             if (null === $oAccountCache) {
                 $oAccount = $self->getAccountFromToken(false);
                 $oAccountCache = $oAccount;
             }
             return $oAccountCache;
         };
         $aCheckableFoldersCache = null;
         $fGetCheckableFolder = function () use($self, &$aCheckableFoldersCache) {
             if (null === $aCheckableFoldersCache) {
                 $oAccount = $self->getAccountFromToken(false);
                 $oSettingsLocal = $self->SettingsProvider(true)->Load($oAccount);
                 $sCheckable = $oSettingsLocal->GetConf('CheckableFolder', '[]');
                 $aCheckable = @\json_decode($sCheckable);
                 if (!\is_array($aCheckable)) {
                     $aCheckable = array();
                 }
                 $aCheckableFoldersCache = $aCheckable;
             }
             return $aCheckableFoldersCache;
         };
         if ($bHasSimpleJsonFunc) {
             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true));
         } else {
             if ('MailSo\\Mail\\Message' === $sClassName) {
                 $oAccount = \call_user_func($fGetAccount);
                 $iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC();
                 if (0 === $iDateTimeStampInUTC || !!$this->Config()->Get('labs', 'date_from_headers', false)) {
                     $iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC();
                     if (0 === $iDateTimeStampInUTC) {
                         $iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC();
                     }
                 }
                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($mResponse->Subject())), 'MessageId' => $mResponse->MessageId(), 'Size' => $mResponse->Size(), 'DateTimeStampInUTC' => $iDateTimeStampInUTC, 'ReplyTo' => $this->responseObject($mResponse->ReplyTo(), $sParent, $aParameters), 'From' => $this->responseObject($mResponse->From(), $sParent, $aParameters), 'To' => $this->responseObject($mResponse->To(), $sParent, $aParameters), 'Cc' => $this->responseObject($mResponse->Cc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($mResponse->Bcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($mResponse->Sender(), $sParent, $aParameters), 'DeliveredTo' => $this->responseObject($mResponse->DeliveredTo(), $sParent, $aParameters), 'Priority' => $mResponse->Priority(), 'Threads' => $mResponse->Threads(), 'Sensitivity' => $mResponse->Sensitivity(), 'ExternalProxy' => false, 'ReadReceipt' => ''));
                 $mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']);
                 $oAttachments = $mResponse->Attachments();
                 $iAttachmentsCount = $oAttachments ? $oAttachments->Count() : 0;
                 $mResult['HasAttachments'] = 0 < $iAttachmentsCount;
                 $mResult['AttachmentsSpecData'] = $mResult['HasAttachments'] ? $oAttachments->SpecData() : array();
                 $sSubject = $mResult['Subject'];
                 $mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']);
                 $mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => (0 === \strlen($sSubject) ? 'message-' . $mResult['Uid'] : \MailSo\Base\Utils::ClearXss($sSubject)) . '.eml'));
                 // Flags
                 $aFlags = $mResponse->FlagsLowerCase();
                 $mResult['IsSeen'] = \in_array('\\seen', $aFlags);
                 $mResult['IsFlagged'] = \in_array('\\flagged', $aFlags);
                 $mResult['IsAnswered'] = \in_array('\\answered', $aFlags);
                 $mResult['IsDeleted'] = \in_array('\\deleted', $aFlags);
                 $sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
                 $sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
                 $mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
                 $mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
                 if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::COMPOSER, $oAccount)) {
                     $mResult['IsReadReceipt'] = true;
                 }
                 $mResult['TextPartIsTrimmed'] = false;
                 if ('Message' === $sParent) {
                     $oAttachments = $mResponse->Attachments();
                     $bHasExternals = false;
                     $mFoundedCIDs = array();
                     $aContentLocationUrls = array();
                     $mFoundedContentLocationUrls = array();
                     if ($oAttachments && 0 < $oAttachments->Count()) {
                         $aList =& $oAttachments->GetAsArray();
                         foreach ($aList as $oAttachment) {
                             if ($oAttachment) {
                                 $sContentLocation = $oAttachment->ContentLocation();
                                 if ($sContentLocation && 0 < \strlen($sContentLocation)) {
                                     $aContentLocationUrls[] = $oAttachment->ContentLocation();
                                 }
                             }
                         }
                     }
                     $sPlain = '';
                     $sHtml = \trim($mResponse->Html());
                     if (0 === \strlen($sHtml)) {
                         $sPlain = \trim($mResponse->Plain());
                     }
                     $mResult['DraftInfo'] = $mResponse->DraftInfo();
                     $mResult['InReplyTo'] = $mResponse->InReplyTo();
                     $mResult['References'] = $mResponse->References();
                     $fAdditionalDomReader = null;
                     if (0 < \strlen($sHtml) && $this->Config()->Get('labs', 'emogrifier', false)) {
                         if (!\class_exists('Pelago\\Emogrifier', false)) {
                             include_once APP_VERSION_ROOT_PATH . 'app/libraries/emogrifier/Emogrifier.php';
                         }
                         if (\class_exists('Pelago\\Emogrifier', false)) {
                             $fAdditionalDomReader = function ($oDom) {
                                 $oEmogrifier = new \Pelago\Emogrifier();
                                 $oEmogrifier->preserveEncoding = false;
                                 return $oEmogrifier->emogrify($oDom);
                             };
                         }
                     }
                     $fAdditionalExternalFilter = null;
                     if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) {
                         $fAdditionalExternalFilter = function ($sUrl) {
                             return './?/ProxyExternal/' . \RainLoop\Utils::EncodeKeyValuesQ(array('Rnd' => \md5(\microtime(true)), 'Token' => \RainLoop\Utils::GetConnectionToken(), 'Url' => $sUrl)) . '/';
                         };
                     }
                     $sHtml = \preg_replace_callback('/(<pre[^>]*>)([\\s\\S\\r\\n\\t]*?)(<\\/pre>)/mi', function ($aMatches) {
                         return \preg_replace('/[\\r\\n]+/', '<br />', $aMatches[1] . \trim($aMatches[2]) . $aMatches[3]);
                     }, $sHtml);
                     $mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false, false, $fAdditionalExternalFilter, $fAdditionalDomReader, !!$this->Config()->Get('labs', 'try_to_detect_hidden_images', false));
                     $mResult['ExternalProxy'] = null !== $fAdditionalExternalFilter;
                     $mResult['Plain'] = $sPlain;
                     //					$mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
                     $mResult['TextHash'] = \md5($mResult['Html'] . $mResult['Plain']);
                     $mResult['TextPartIsTrimmed'] = $mResponse->TextPartIsTrimmed();
                     $mResult['PgpSigned'] = $mResponse->PgpSigned();
                     $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();
                     $mResult['PgpSignature'] = $mResponse->PgpSignature();
                     unset($sHtml, $sPlain);
                     $mResult['HasExternals'] = $bHasExternals;
                     $mResult['HasInternals'] = \is_array($mFoundedCIDs) && 0 < \count($mFoundedCIDs) || \is_array($mFoundedContentLocationUrls) && 0 < \count($mFoundedContentLocationUrls);
                     $mResult['FoundedCIDs'] = $mFoundedCIDs;
                     $mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array('FoundedCIDs' => $mFoundedCIDs, 'FoundedContentLocationUrls' => $mFoundedContentLocationUrls)));
                     $mResult['ReadReceipt'] = $mResponse->ReadReceipt();
                     if (0 < \strlen($mResult['ReadReceipt']) && !$mResult['IsReadReceipt']) {
                         if (0 < \strlen($mResult['ReadReceipt'])) {
                             try {
                                 $oReadReceipt = \MailSo\Mime\Email::Parse($mResult['ReadReceipt']);
                                 if (!$oReadReceipt) {
                                     $mResult['ReadReceipt'] = '';
                                 }
                             } catch (\Exception $oException) {
                                 unset($oException);
                             }
                         }
                         if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher($oAccount)->Get(\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $mResult['Folder'], $mResult['Uid']), '0')) {
                             $mResult['ReadReceipt'] = '';
                         }
                     }
                 }
             } else {
                 if ('MailSo\\Mime\\Email' === $sClassName) {
                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()), 'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail(true)), 'DkimStatus' => $mResponse->GetDkimStatus(), 'DkimValue' => $mResponse->GetDkimValue()));
                 } else {
                     if ('RainLoop\\Providers\\AddressBook\\Classes\\Contact' === $sClassName) {
                         $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContact' => $mResponse->IdContact, 'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display), 'ReadOnly' => $mResponse->ReadOnly, 'IdPropertyFromSearch' => $mResponse->IdPropertyFromSearch, 'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters)));
                     } else {
                         if ('RainLoop\\Providers\\AddressBook\\Classes\\Tag' === $sClassName) {
                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContactTag' => $mResponse->IdContactTag, 'Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->Name), 'ReadOnly' => $mResponse->ReadOnly));
                         } else {
                             if ('RainLoop\\Providers\\AddressBook\\Classes\\Property' === $sClassName) {
                                 // Simple hack
                                 if ($mResponse && $mResponse->IsWeb()) {
                                     $mResponse->Value = \preg_replace('/(skype|ftp|http[s]?)\\\\:\\/\\//i', '$1://', $mResponse->Value);
                                 }
                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdProperty' => $mResponse->IdProperty, 'Type' => $mResponse->Type, 'TypeStr' => $mResponse->TypeStr, 'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value)));
                             } else {
                                 if ('MailSo\\Mail\\Attachment' === $sClassName) {
                                     $oAccount = $this->getAccountFromToken(false);
                                     $mFoundedCIDs = isset($aParameters['FoundedCIDs']) && \is_array($aParameters['FoundedCIDs']) && 0 < \count($aParameters['FoundedCIDs']) ? $aParameters['FoundedCIDs'] : null;
                                     $mFoundedContentLocationUrls = isset($aParameters['FoundedContentLocationUrls']) && \is_array($aParameters['FoundedContentLocationUrls']) && 0 < \count($aParameters['FoundedContentLocationUrls']) ? $aParameters['FoundedContentLocationUrls'] : null;
                                     if ($mFoundedCIDs || $mFoundedContentLocationUrls) {
                                         $mFoundedCIDs = \array_merge($mFoundedCIDs ? $mFoundedCIDs : array(), $mFoundedContentLocationUrls ? $mFoundedContentLocationUrls : array());
                                         $mFoundedCIDs = 0 < \count($mFoundedCIDs) ? $mFoundedCIDs : null;
                                     }
                                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Framed' => false, 'MimeIndex' => (string) $mResponse->MimeIndex(), 'MimeType' => $mResponse->MimeType(), 'FileName' => \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::ClearXss($mResponse->FileName(true))), 'EstimatedSize' => $mResponse->EstimatedSize(), 'CID' => $mResponse->Cid(), 'ContentLocation' => $mResponse->ContentLocation(), 'IsInline' => $mResponse->IsInline(), 'IsThumbnail' => $bThumb, 'IsLinked' => $mFoundedCIDs && \in_array(\trim(\trim($mResponse->Cid()), '<>'), $mFoundedCIDs) || $mFoundedContentLocationUrls && \in_array(\trim($mResponse->ContentLocation()), $mFoundedContentLocationUrls)));
                                     $mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']);
                                     if ($mResult['IsThumbnail']) {
                                         $mResult['IsThumbnail'] = $this->isFileHasThumbnail($mResult['FileName']);
                                     }
                                     $mResult['Download'] = \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeIndex' => $mResult['MimeIndex'], 'MimeType' => $mResult['MimeType'], 'FileName' => $mResult['FileName'], 'Framed' => $mResult['Framed']));
                                 } else {
                                     if ('MailSo\\Mail\\Folder' === $sClassName) {
                                         $aExtended = null;
                                         //				$mStatus = $mResponse->Status();
                                         //				if (\is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT']))
                                         //				{
                                         //					$aExtended = array(
                                         //						'MessageCount' => (int) $mStatus['MESSAGES'],
                                         //						'MessageUnseenCount' => (int) $mStatus['UNSEEN'],
                                         //						'UidNext' => (string) $mStatus['UIDNEXT'],
                                         //						'Hash' => $this->MailClient()->GenerateFolderHash(
                                         //							$mResponse->FullNameRaw(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'],
                                         //								empty($mStatus['HIGHESTMODSEQ']) ? '' : $mStatus['HIGHESTMODSEQ'])
                                         //					);
                                         //				}
                                         $aCheckableFolder = \call_user_func($fGetCheckableFolder);
                                         if (!\is_array($aCheckableFolder)) {
                                             $aCheckableFolder = array();
                                         }
                                         $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => $mResponse->Name(), 'FullName' => $mResponse->FullName(), 'FullNameRaw' => $mResponse->FullNameRaw(), 'FullNameHash' => $this->hashFolderFullName($mResponse->FullNameRaw(), $mResponse->FullName()), 'Delimiter' => (string) $mResponse->Delimiter(), 'HasVisibleSubFolders' => $mResponse->HasVisibleSubFolders(), 'IsSubscribed' => $mResponse->IsSubscribed(), 'IsExists' => $mResponse->IsExists(), 'IsSelectable' => $mResponse->IsSelectable(), 'Flags' => $mResponse->FlagsLowerCase(), 'Checkable' => \in_array($mResponse->FullNameRaw(), $aCheckableFolder), 'Extended' => $aExtended, 'SubFolders' => $this->responseObject($mResponse->SubFolders(), $sParent, $aParameters)));
                                     } else {
                                         if ('MailSo\\Mail\\MessageCollection' === $sClassName) {
                                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('MessageCount' => $mResponse->MessageCount, 'MessageUnseenCount' => $mResponse->MessageUnseenCount, 'MessageResultCount' => $mResponse->MessageResultCount, 'Folder' => $mResponse->FolderName, 'FolderHash' => $mResponse->FolderHash, 'UidNext' => $mResponse->UidNext, 'ThreadUid' => $mResponse->ThreadUid, 'NewMessages' => $this->responseObject($mResponse->NewMessages), 'Filtered' => $mResponse->Filtered, 'Offset' => $mResponse->Offset, 'Limit' => $mResponse->Limit, 'Search' => $mResponse->Search));
                                         } else {
                                             if ('MailSo\\Mail\\AttachmentCollection' === $sClassName) {
                                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('InlineCount' => $mResponse->InlineCount()));
                                             } else {
                                                 if ('MailSo\\Mail\\FolderCollection' === $sClassName) {
                                                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Namespace' => $mResponse->GetNamespace(), 'FoldersHash' => isset($mResponse->FoldersHash) ? $mResponse->FoldersHash : '', 'IsThreadsSupported' => $mResponse->IsThreadsSupported, 'Optimized' => $mResponse->Optimized, 'CountRec' => $mResponse->CountRec(), 'SystemFolders' => isset($mResponse->SystemFolders) && \is_array($mResponse->SystemFolders) ? $mResponse->SystemFolders : array()));
                                                 } else {
                                                     if ($mResponse instanceof \MailSo\Base\Collection) {
                                                         $aList =& $mResponse->GetAsArray();
                                                         if (100 < \count($aList) && $mResponse instanceof \MailSo\Mime\EmailCollection) {
                                                             $aList = \array_slice($aList, 0, 100);
                                                         }
                                                         $mResult = $this->responseObject($aList, $sParent, $aParameters);
                                                         $bHook = false;
                                                     } else {
                                                         $mResult = '["' . \get_class($mResponse) . '"]';
                                                         $bHook = false;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($bHook) {
             $this->Plugins()->RunHook('filter.response-object', array($sClassName, $mResult), false);
         }
     } else {
         if (\is_array($mResponse)) {
             foreach ($mResponse as $iKey => $oItem) {
                 $mResponse[$iKey] = $this->responseObject($oItem, $sParent, $aParameters);
             }
             $mResult = $mResponse;
         }
     }
     unset($mResponse);
     return $mResult;
 }
예제 #6
0
 /**
  * @param string $sFolder
  * @param \MailSo\Imap\FetchResponse $oFetchResponse
  * @param \MailSo\Imap\BodyStructure $oBodyStructure = null
  *
  * @return \MailSo\Mail\Message
  */
 public function InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure = null)
 {
     if (!$oBodyStructure) {
         $oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
     }
     $sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
     $sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
     $sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
     $aFlags = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS);
     $this->sFolder = $sFolder;
     $this->iUid = \is_numeric($sUid) ? (int) $sUid : 0;
     $this->iSize = \is_numeric($sSize) ? (int) $sSize : 0;
     $this->aFlags = \is_array($aFlags) ? $aFlags : array();
     $this->aFlagsLowerCase = \array_map('strtolower', $this->aFlags);
     $this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
     $sCharset = $oBodyStructure ? $oBodyStructure->SearchCharset() : '';
     $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
     $sHeaders = $oFetchResponse->GetHeaderFieldsValue();
     if (0 < \strlen($sHeaders)) {
         $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders, false, $sCharset);
         $sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
         if (0 < \strlen($sContentTypeCharset)) {
             $sCharset = $sContentTypeCharset;
             $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
         }
         if (0 < \strlen($sCharset)) {
             $oHeaders->SetParentCharset($sCharset);
         }
         $bCharsetAutoDetect = 0 === \strlen($sCharset);
         $this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
         $this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
         $this->sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
         $this->oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, $bCharsetAutoDetect);
         $this->oTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::TO_, $bCharsetAutoDetect);
         $this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
         $this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
         $this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
         $this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
         $this->oDeliveredTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::DELIVERED_TO, $bCharsetAutoDetect);
         $this->sInReplyTo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IN_REPLY_TO);
         $this->sReferences = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES);
         $sHeaderDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
         $this->sHeaderDate = $sHeaderDate;
         $this->iHeaderTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sHeaderDate);
         // Sensitivity
         $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING;
         $sSensitivity = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SENSITIVITY);
         switch (\strtolower($sSensitivity)) {
             case 'personal':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PERSONAL;
                 break;
             case 'private':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_;
                 break;
             case 'company-confidential':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL;
                 break;
         }
         // Priority
         $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
         $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
         if (0 === \strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
         }
         if (0 === \strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
         }
         if (0 < \strlen($sPriority)) {
             switch (\str_replace(' ', '', \strtolower($sPriority))) {
                 case 'high':
                 case '1(highest)':
                 case '2(high)':
                 case '1':
                 case '2':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::HIGH;
                     break;
                 case 'low':
                 case '4(low)':
                 case '5(lowest)':
                 case '4':
                 case '5':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::LOW;
                     break;
             }
         }
         // Delivery Receipt
         $this->sDeliveryReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::RETURN_RECEIPT_TO));
         // Read Receipt
         $this->sReadReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO));
         if (empty($this->sReadReceipt)) {
             $this->sReadReceipt = \trim($oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO));
         }
         $sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
         if (0 < \strlen($sDraftInfo)) {
             $sType = '';
             $sFolder = '';
             $sUid = '';
             \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo)->ForeachList(function ($oParameter) use(&$sType, &$sFolder, &$sUid) {
                 switch (\strtolower($oParameter->Name())) {
                     case 'type':
                         $sType = $oParameter->Value();
                         break;
                     case 'uid':
                         $sUid = $oParameter->Value();
                         break;
                     case 'folder':
                         $sFolder = \base64_decode($oParameter->Value());
                         break;
                 }
             });
             if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid)) {
                 $this->aDraftInfo = array($sType, $sUid, $sFolder);
             }
         }
     } else {
         if ($oFetchResponse->GetEnvelope()) {
             if (0 === \strlen($sCharset) && $oBodyStructure) {
                 $sCharset = $oBodyStructure->SearchCharset();
                 $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
             }
             if (0 === \strlen($sCharset)) {
                 $sCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
             }
             // date, subject, from, sender, reply-to, to, cc, bcc, in-reply-to, message-id
             $this->sMessageId = $oFetchResponse->GetFetchEnvelopeValue(9, '');
             $this->sSubject = \MailSo\Base\Utils::DecodeHeaderValue($oFetchResponse->GetFetchEnvelopeValue(1, ''), $sCharset);
             $this->oFrom = $oFetchResponse->GetFetchEnvelopeEmailCollection(2, $sCharset);
             $this->oSender = $oFetchResponse->GetFetchEnvelopeEmailCollection(3, $sCharset);
             $this->oReplyTo = $oFetchResponse->GetFetchEnvelopeEmailCollection(4, $sCharset);
             $this->oTo = $oFetchResponse->GetFetchEnvelopeEmailCollection(5, $sCharset);
             $this->oCc = $oFetchResponse->GetFetchEnvelopeEmailCollection(6, $sCharset);
             $this->oBcc = $oFetchResponse->GetFetchEnvelopeEmailCollection(7, $sCharset);
             $this->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, '');
         }
     }
     $aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
     if (\is_array($aTextParts) && 0 < \count($aTextParts)) {
         if (0 === \strlen($sCharset)) {
             $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
         }
         $sHtmlParts = array();
         $sPlainParts = array();
         foreach ($aTextParts as $oPart) {
             $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ']');
             if (null === $sText) {
                 $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ']<0>');
                 if (\is_string($sText) && 0 < \strlen($sText)) {
                     $this->bTextPartIsTrimmed = true;
                 }
             }
             if (\is_string($sText) && 0 < \strlen($sText)) {
                 $sTextCharset = $oPart->Charset();
                 if (empty($sTextCharset)) {
                     $sTextCharset = $sCharset;
                 }
                 $sTextCharset = \MailSo\Base\Utils::NormalizeCharset($sTextCharset, true);
                 $sText = \MailSo\Base\Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName());
                 $sText = \MailSo\Base\Utils::ConvertEncoding($sText, $sTextCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
                 $sText = \MailSo\Base\Utils::Utf8Clear($sText);
                 if ('text/html' === $oPart->ContentType()) {
                     $sHtmlParts[] = $sText;
                 } else {
                     $sPlainParts[] = $sText;
                 }
             }
         }
         if (0 < \count($sHtmlParts)) {
             $this->sHtml = \implode('<br />', $sHtmlParts);
         } else {
             $this->sPlain = \trim(\implode("\n", $sPlainParts));
         }
         $aMatch = array();
         if (\preg_match('/-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0])) {
             $this->sPgpSignature = \trim($aMatch[0]);
             $this->bPgpSigned = true;
         }
         $aMatch = array();
         if (\preg_match('/-----BEGIN PGP MESSAGE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0])) {
             $this->bPgpEncrypted = true;
         }
         unset($sHtmlParts, $sPlainParts, $aMatch);
     }
     //		if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) &&
     //			'application/pgp-signature' === \strtolower($oHeaders->ParameterValue(
     //				\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
     //				\MailSo\Mime\Enumerations\Parameter::PROTOCOL
     //			)))
     //		{
     //			$aPgpSignatureParts = $oBodyStructure ? $oBodyStructure->SearchByContentType('application/pgp-signature') : null;
     //			if (\is_array($aPgpSignatureParts) && 0 < \count($aPgpSignatureParts) && isset($aPgpSignatureParts[0]))
     //			{
     //				$sPgpSignatureText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$aPgpSignatureParts[0]->PartID().']');
     //				if (\is_string($sPgpSignatureText) && 0 < \strlen($sPgpSignatureText) && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE'))
     //				{
     //					$this->sPgpSignature = \trim($sPgpSignatureText);
     //					$this->bPgpSigned = true;
     //				}
     //			}
     //		}
     if ($oBodyStructure) {
         $aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
         if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) {
             $this->oAttachments = AttachmentCollection::NewInstance();
             foreach ($aAttachmentsParts as $oAttachmentItem) {
                 $this->oAttachments->Add(\MailSo\Mail\Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem));
             }
         }
     }
     return $this;
 }
예제 #7
0
 public function PopulateByVCard($sVCard, $sEtag = '')
 {
     $this->Properties = array();
     if (!empty($sEtag)) {
         $this->Etag = $sEtag;
     }
     try {
         $oVCard = \Sabre\VObject\Reader::read($sVCard);
     } catch (\Exception $oExc) {
     }
     $aProperties = array();
     if ($oVCard) {
         $bOldVersion = empty($oVCard->VERSION) ? false : \in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));
         $this->IdContactStr = $oVCard->UID ? (string) $oVCard->UID : \Sabre\DAV\UUIDUtil::getUUID();
         if (isset($oVCard->FN) && '' !== \trim($oVCard->FN)) {
             $sValue = $this->getPropertyValueHelper($oVCard->FN, $bOldVersion);
             $aProperties[] = new Property(PropertyType::FULLNAME, $sValue);
         }
         if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME)) {
             $sValue = $sValue = $this->getPropertyValueHelper($oVCard->NICKNAME, $bOldVersion);
             $aProperties[] = new Property(PropertyType::NICK_NAME, $sValue);
         }
         if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE)) {
             $sValue = $this->getPropertyValueHelper($oVCard->NOTE, $bOldVersion);
             $aProperties[] = new Property(PropertyType::NOTE, $sValue);
         }
         if (isset($oVCard->N)) {
             $aNames = $oVCard->N->getParts();
             foreach ($aNames as $iIndex => $sValue) {
                 $sValue = \trim($sValue);
                 if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET'])) {
                     if (0 < \strlen($sValue)) {
                         $sEncValue = @\utf8_encode($sValue);
                         if (0 === \strlen($sEncValue)) {
                             $sEncValue = $sValue;
                         }
                         $sValue = $sEncValue;
                     }
                 }
                 $sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
                 switch ($iIndex) {
                     case 0:
                         $aProperties[] = new Property(PropertyType::LAST_NAME, $sValue);
                         break;
                     case 1:
                         $aProperties[] = new Property(PropertyType::FIRST_NAME, $sValue);
                         break;
                     case 2:
                         $aProperties[] = new Property(PropertyType::MIDDLE_NAME, $sValue);
                         break;
                     case 3:
                         $aProperties[] = new Property(PropertyType::NAME_PREFIX, $sValue);
                         break;
                     case 4:
                         $aProperties[] = new Property(PropertyType::NAME_SUFFIX, $sValue);
                         break;
                 }
             }
         }
         if (isset($oVCard->EMAIL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->EMAIL, PropertyType::EMAIl);
         }
         if (isset($oVCard->URL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->URL, PropertyType::WEB_PAGE);
         }
         if (isset($oVCard->TEL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->TEL, PropertyType::PHONE);
         }
         $this->Properties = $aProperties;
         if (isset($oVCard->CATEGORIES)) {
             $this->Tags = (array) $oVCard->CATEGORIES->getParts();
             $this->Tags = \is_array($this->Tags) ? $this->Tags : array();
             $this->Tags = \array_map('trim', $this->Tags);
         }
     }
     $this->UpdateDependentValues();
 }
예제 #8
0
 /**
  * @param string $sRawFolderFullName
  * @param \MailSo\Imap\FetchResponse $oFetchResponse
  * @param \MailSo\Imap\BodyStructure $oBodyStructure = null
  * @param array $aAscPartsIds = array()
  *
  * @return CApiMailMessage
  */
 public function InitByFetchResponse($sRawFolderFullName, $oFetchResponse, $oBodyStructure = null, $sRfc822SubMimeIndex = '', $aAscPartsIds = array())
 {
     if (!$oBodyStructure) {
         $oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
     }
     $aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : array();
     $aICalPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/calendar') : null;
     $oICalPart = is_array($aICalPart) && 0 < count($aICalPart) ? $aICalPart[0] : null;
     $aVCardPart = $oBodyStructure ? $oBodyStructure->SearchByContentType('text/vcard') : null;
     $aVCardPart = $aVCardPart ? $aVCardPart : ($oBodyStructure ? $oBodyStructure->SearchByContentType('text/x-vcard') : null);
     $oVCardPart = is_array($aVCardPart) && 0 < count($aVCardPart) ? $aVCardPart[0] : null;
     $sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
     $sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
     $sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
     $aFlags = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS);
     $this->sFolder = $sRawFolderFullName;
     $this->iUid = is_numeric($sUid) ? (int) $sUid : 0;
     $this->iSize = is_numeric($sSize) ? (int) $sSize : 0;
     $this->iTextSize = 0;
     $this->aFlags = is_array($aFlags) ? $aFlags : array();
     $this->aFlagsLowerCase = array_map('strtolower', $this->aFlags);
     $this->iInternalTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseInternalDateString($sInternalDate);
     if ($oICalPart) {
         $sICal = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oICalPart->PartID() . ']');
         if (!empty($sICal)) {
             $sICal = \MailSo\Base\Utils::DecodeEncodingValue($sICal, $oICalPart->MailEncodingName());
             $sICal = \MailSo\Base\Utils::ConvertEncoding($sICal, \MailSo\Base\Utils::NormalizeCharset($oICalPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
             if (!empty($sICal) && false !== strpos($sICal, 'BEGIN:VCALENDAR')) {
                 $sICal = preg_replace('/(.*)(BEGIN[:]VCALENDAR(.+)END[:]VCALENDAR)(.*)/ms', '$2', $sICal);
             } else {
                 $sICal = '';
             }
             if (!empty($sICal)) {
                 $this->AddExtend('ICAL_RAW', $sICal);
             }
         }
     }
     if ($oVCardPart) {
         $sVCard = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oVCardPart->PartID() . ']');
         if (!empty($sVCard)) {
             $sVCard = \MailSo\Base\Utils::DecodeEncodingValue($sVCard, $oVCardPart->MailEncodingName());
             $sVCard = \MailSo\Base\Utils::ConvertEncoding($sVCard, \MailSo\Base\Utils::NormalizeCharset($oVCardPart->Charset(), true), \MailSo\Base\Enumerations\Charset::UTF_8);
             if (!empty($sVCard) && false !== strpos($sVCard, 'BEGIN:VCARD')) {
                 $sVCard = preg_replace('/(.*)(BEGIN\\:VCARD(.+)END\\:VCARD)(.*)/ms', '$2', $sVCard);
             } else {
                 $sVCard = '';
             }
             if (!empty($sVCard)) {
                 $this->AddExtend('VCARD_RAW', $sVCard);
             }
         }
     }
     $sCharset = $oBodyStructure ? $oBodyStructure->SearchCharset() : '';
     $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
     $this->sHeaders = trim($oFetchResponse->GetHeaderFieldsValue($sRfc822SubMimeIndex));
     if (!empty($this->sHeaders)) {
         $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($this->sHeaders, false, $sCharset);
         $sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
         if (!empty($sContentTypeCharset)) {
             $sCharset = $sContentTypeCharset;
             $sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
         }
         if (!empty($sCharset)) {
             $oHeaders->SetParentCharset($sCharset);
         }
         $bCharsetAutoDetect = 0 === \strlen($sCharset);
         $this->sSubject = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, $bCharsetAutoDetect);
         $this->sMessageId = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::MESSAGE_ID);
         $this->sContentType = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE);
         $aReceived = $oHeaders->ValuesByName(\MailSo\Mime\Enumerations\Header::RECEIVED);
         $sReceived = !empty($aReceived[0]) ? trim($aReceived[0]) : '';
         $sDate = '';
         if (!empty($sReceived)) {
             $aParts = explode(';', $sReceived);
             if (0 < count($aParts)) {
                 $aParts = array_reverse($aParts);
                 foreach ($aParts as $sReceiveLine) {
                     $sReceiveLine = trim($sReceiveLine);
                     if (preg_match('/[\\d]{4} [\\d]{2}:[\\d]{2}:[\\d]{2} /', $sReceiveLine)) {
                         $sDate = $sReceiveLine;
                         break;
                     }
                 }
             }
         }
         if (empty($sDate)) {
             $sDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
         }
         if (!empty($sDate)) {
             $this->iReceivedOrDateTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDate);
         }
         $this->oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, $bCharsetAutoDetect);
         $this->oTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::TO_, $bCharsetAutoDetect);
         $this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
         $this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
         $this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
         $this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
         $this->sInReplyTo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IN_REPLY_TO);
         $this->sReferences = \preg_replace('/[\\s]+/', ' ', $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES));
         // Sensitivity
         $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING;
         $sSensitivity = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SENSITIVITY);
         switch (strtolower($sSensitivity)) {
             case 'personal':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PERSONAL;
                 break;
             case 'private':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_;
                 break;
             case 'company-confidential':
                 $this->iSensitivity = \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL;
                 break;
         }
         // Priority
         $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::NORMAL;
         $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY);
         if (0 === strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IMPORTANCE);
         }
         if (0 === strlen($sPriority)) {
             $sPriority = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_PRIORITY);
         }
         if (0 < strlen($sPriority)) {
             switch (str_replace(' ', '', strtolower($sPriority))) {
                 case 'high':
                 case '1(highest)':
                 case '2(high)':
                 case '1':
                 case '2':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::HIGH;
                     break;
                 case 'low':
                 case '4(low)':
                 case '5(lowest)':
                 case '4':
                 case '5':
                     $this->iPriority = \MailSo\Mime\Enumerations\MessagePriority::LOW;
                     break;
             }
         }
         // ReadingConfirmation
         $this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO);
         if (0 === strlen($this->sReadingConfirmation)) {
             $this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO);
         }
         $this->sReadingConfirmation = trim($this->sReadingConfirmation);
         $sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
         if (0 < strlen($sDraftInfo)) {
             $sType = '';
             $sFolder = '';
             $sUid = '';
             \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo)->ForeachList(function ($oParameter) use(&$sType, &$sFolder, &$sUid) {
                 switch (strtolower($oParameter->Name())) {
                     case 'type':
                         $sType = $oParameter->Value();
                         break;
                     case 'uid':
                         $sUid = $oParameter->Value();
                         break;
                     case 'folder':
                         $sFolder = base64_decode($oParameter->Value());
                         break;
                 }
             });
             if (0 < strlen($sType) && 0 < strlen($sFolder) && 0 < strlen($sUid)) {
                 $this->aDraftInfo = array($sType, $sUid, $sFolder);
             }
         }
         \CApi::Plugin()->RunHook('api-mail-message-headers-parse', array(&$this, $oHeaders));
     }
     if (is_array($aTextParts) && 0 < count($aTextParts)) {
         if (0 === \strlen($sCharset)) {
             $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
         }
         $sHtmlParts = array();
         $sPlainParts = array();
         $iHtmlSize = 0;
         $iPlainSize = 0;
         foreach ($aTextParts as $oPart) {
             if ($oPart) {
                 if ('text/html ' === $oPart->ContentType()) {
                     $iHtmlSize += $oPart->EstimatedSize();
                 } else {
                     $iPlainSize += $oPart->EstimatedSize();
                 }
             }
             $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '') . ']');
             //				if (null === $sText)
             //				{
             //					$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().
             //						('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '').']<0>');
             //				}
             if (is_string($sText) && 0 < strlen($sText)) {
                 $sTextCharset = $oPart->Charset();
                 if (empty($sTextCharset)) {
                     $sTextCharset = $sCharset;
                 }
                 $sTextCharset = \MailSo\Base\Utils::NormalizeCharset($sTextCharset, true);
                 $sText = \MailSo\Base\Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName());
                 $sText = \MailSo\Base\Utils::ConvertEncoding($sText, $sTextCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
                 $sText = \MailSo\Base\Utils::Utf8Clear($sText);
                 if ('text/html' === $oPart->ContentType()) {
                     $sHtmlParts[] = $sText;
                 } else {
                     $sPlainParts[] = $sText;
                 }
             }
         }
         if (0 < count($sHtmlParts)) {
             $this->sHtml = trim(implode('<br />', $sHtmlParts));
             $this->iTextSize = strlen($this->sHtml);
         } else {
             $this->sPlain = trim(implode("\n", $sPlainParts));
             $this->iTextSize = strlen($this->sPlain);
         }
         if (0 === $this->iTextSize) {
             $this->iTextSize = 0 < $iHtmlSize ? $iHtmlSize : $iPlainSize;
         }
         unset($sHtmlParts, $sPlainParts);
     }
     if ($oBodyStructure) {
         $aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
         if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) {
             $this->oAttachments = CApiMailAttachmentCollection::NewInstance();
             foreach ($aAttachmentsParts as $oAttachmentItem) {
                 $this->oAttachments->Add(CApiMailAttachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem));
             }
             $this->oAttachments->ForeachList(function ($oAttachment) use($aAscPartsIds, $oFetchResponse) {
                 if ($oAttachment && in_array($oAttachment->MimeIndex(), $aAscPartsIds)) {
                     $mContent = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oAttachment->MimeIndex() . ']');
                     if (is_string($mContent)) {
                         $oAttachment->SetContent(\MailSo\Base\Utils::DecodeEncodingValue($mContent, $oAttachment->ContentTransferEncoding()));
                     }
                 }
             });
         }
     }
     \CApi::Plugin()->RunHook('api-mail-message-parse', array(&$this, $oFetchResponse, $oBodyStructure, $sRfc822SubMimeIndex));
     return $this;
 }
예제 #9
0
 public function PopulateByVCard($sUid, $sVCard, $sEtag = '', $oLogger = null)
 {
     if ("" === \substr($sVCard, 0, 3)) {
         $sVCard = \substr($sVCard, 3);
     }
     $this->Properties = array();
     if (!\class_exists('SabreForRainLoop\\DAV\\Client')) {
         return false;
     }
     if (!empty($sEtag)) {
         $this->Etag = $sEtag;
     }
     $this->IdContactStr = $sUid;
     try {
         $oVCard = \SabreForRainLoop\VObject\Reader::read($sVCard);
     } catch (\Exception $oExc) {
         if ($oLogger) {
             $oLogger->WriteException($oExc);
             $oLogger->WriteDump($sVCard);
         }
     }
     //		if ($oLogger)
     //		{
     //			$oLogger->WriteDump($sVCard);
     //		}
     $bOwnCloud = false;
     $aProperties = array();
     if ($oVCard) {
         $bOwnCloud = empty($oVCard->PRODID) ? false : false !== \strpos(\strtolower($oVCard->PRODID), 'owncloud');
         $bOldVersion = empty($oVCard->VERSION) ? false : \in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));
         if (isset($oVCard->FN) && '' !== \trim($oVCard->FN)) {
             $sValue = $this->getPropertyValueHelper($oVCard->FN, $bOldVersion);
             $aProperties[] = new Property(PropertyType::FULLNAME, $sValue);
         }
         if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME)) {
             $sValue = $sValue = $this->getPropertyValueHelper($oVCard->NICKNAME, $bOldVersion);
             $aProperties[] = new Property(PropertyType::NICK_NAME, $sValue);
         }
         if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE)) {
             $sValue = $this->getPropertyValueHelper($oVCard->NOTE, $bOldVersion);
             $aProperties[] = new Property(PropertyType::NOTE, $sValue);
         }
         if (isset($oVCard->N)) {
             $aNames = $oVCard->N->getParts();
             foreach ($aNames as $iIndex => $sValue) {
                 $sValue = \trim($sValue);
                 if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET'])) {
                     if (0 < \strlen($sValue)) {
                         $sEncValue = @\utf8_encode($sValue);
                         if (0 === \strlen($sEncValue)) {
                             $sEncValue = $sValue;
                         }
                         $sValue = $sEncValue;
                     }
                 }
                 $sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
                 switch ($iIndex) {
                     case 0:
                         $aProperties[] = new Property(PropertyType::LAST_NAME, $sValue);
                         break;
                     case 1:
                         $aProperties[] = new Property(PropertyType::FIRST_NAME, $sValue);
                         break;
                     case 2:
                         $aProperties[] = new Property(PropertyType::MIDDLE_NAME, $sValue);
                         break;
                     case 3:
                         $aProperties[] = new Property(PropertyType::NAME_PREFIX, $sValue);
                         break;
                     case 4:
                         $aProperties[] = new Property(PropertyType::NAME_SUFFIX, $sValue);
                         break;
                 }
             }
         }
         if (isset($oVCard->EMAIL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->EMAIL, PropertyType::EMAIl);
         }
         if (isset($oVCard->URL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->URL, PropertyType::WEB_PAGE);
         }
         if (isset($oVCard->TEL)) {
             $this->addArrayPropertyHelper($aProperties, $oVCard->TEL, PropertyType::PHONE);
         }
         $sUidValue = $oVCard->UID ? (string) $oVCard->UID : \SabreForRainLoop\DAV\UUIDUtil::getUUID();
         $aProperties[] = new Property(PropertyType::UID, $sUidValue);
         if (empty($this->IdContactStr)) {
             $this->IdContactStr = $sUidValue;
         }
         $this->Properties = $aProperties;
     }
     $this->UpdateDependentValues();
     return true;
 }
예제 #10
0
 /**
  * @param mixed $mResponse
  * @param string $sParent
  * @param array $aParameters = array()
  *
  * @return mixed
  */
 protected function responseObject($mResponse, $sParent = '', $aParameters = array())
 {
     $mResult = $mResponse;
     if (\is_object($mResponse)) {
         $bHook = true;
         $sClassName = \get_class($mResponse);
         $bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON');
         $bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS);
         if ($bHasSimpleJsonFunc) {
             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true));
         } else {
             if ('MailSo\\Mail\\Message' === $sClassName) {
                 $oAccount = $this->getAccountFromToken(false);
                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($mResponse->Subject())), 'MessageId' => $mResponse->MessageId(), 'Size' => $mResponse->Size(), 'DateTimeStampInUTC' => !!$this->Config()->Get('labs', 'date_from_headers', false) ? $mResponse->HeaderTimeStampInUTC() : $mResponse->InternalTimeStampInUTC(), 'ReplyTo' => $this->responseObject($mResponse->ReplyTo(), $sParent, $aParameters), 'From' => $this->responseObject($mResponse->From(), $sParent, $aParameters), 'To' => $this->responseObject($mResponse->To(), $sParent, $aParameters), 'Cc' => $this->responseObject($mResponse->Cc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($mResponse->Bcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($mResponse->Sender(), $sParent, $aParameters), 'DeliveredTo' => $this->responseObject($mResponse->DeliveredTo(), $sParent, $aParameters), 'Priority' => $mResponse->Priority(), 'Threads' => $mResponse->Threads(), 'ThreadsLen' => $mResponse->ThreadsLen(), 'ParentThread' => $mResponse->ParentThread(), 'Sensitivity' => $mResponse->Sensitivity(), 'ExternalProxy' => false, 'ReadReceipt' => ''));
                 $mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']);
                 $oAttachments = $mResponse->Attachments();
                 $iAttachmentsCount = $oAttachments ? $oAttachments->Count() : 0;
                 $mResult['HasAttachments'] = 0 < $iAttachmentsCount;
                 $mResult['AttachmentsMainType'] = '';
                 if (0 < $iAttachmentsCount) {
                     switch (true) {
                         case $iAttachmentsCount === $oAttachments->ImageCount():
                             $mResult['AttachmentsMainType'] = 'image';
                             break;
                         case $iAttachmentsCount === $oAttachments->ArchiveCount():
                             $mResult['AttachmentsMainType'] = 'archive';
                             break;
                         case $iAttachmentsCount === $oAttachments->PdfCount():
                             $mResult['AttachmentsMainType'] = 'pdf';
                             break;
                         case $iAttachmentsCount === $oAttachments->DocCount():
                             $mResult['AttachmentsMainType'] = 'doc';
                             break;
                         case $iAttachmentsCount === $oAttachments->CertificateCount():
                             $mResult['AttachmentsMainType'] = 'certificate';
                             break;
                     }
                 }
                 $sSubject = $mResult['Subject'];
                 $mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']);
                 $mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValues(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => (0 === \strlen($sSubject) ? 'message-' . $mResult['Uid'] : \MailSo\Base\Utils::ClearXss($sSubject)) . '.eml'));
                 // Flags
                 $aFlags = $mResponse->FlagsLowerCase();
                 $mResult['IsSeen'] = \in_array('\\seen', $aFlags);
                 $mResult['IsFlagged'] = \in_array('\\flagged', $aFlags);
                 $mResult['IsAnswered'] = \in_array('\\answered', $aFlags);
                 $mResult['IsDeleted'] = \in_array('\\deleted', $aFlags);
                 $sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
                 $sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
                 $mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
                 $mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
                 $mResult['TextPartIsTrimmed'] = false;
                 if ('Message' === $sParent) {
                     $oAttachments = $mResponse->Attachments();
                     $bHasExternals = false;
                     $mFoundedCIDs = array();
                     $aContentLocationUrls = array();
                     $mFoundedContentLocationUrls = array();
                     if ($oAttachments && 0 < $oAttachments->Count()) {
                         $aList =& $oAttachments->GetAsArray();
                         foreach ($aList as $oAttachment) {
                             if ($oAttachment) {
                                 $sContentLocation = $oAttachment->ContentLocation();
                                 if ($sContentLocation && 0 < \strlen($sContentLocation)) {
                                     $aContentLocationUrls[] = $oAttachment->ContentLocation();
                                 }
                             }
                         }
                     }
                     $sPlain = '';
                     $sHtml = \trim($mResponse->Html());
                     if (0 === \strlen($sHtml)) {
                         $sPlain = \trim($mResponse->Plain());
                     }
                     $mResult['DraftInfo'] = $mResponse->DraftInfo();
                     $mResult['InReplyTo'] = $mResponse->InReplyTo();
                     $mResult['References'] = $mResponse->References();
                     $fAdditionalExternalFilter = null;
                     if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) {
                         $fAdditionalExternalFilter = function ($sUrl) {
                             return './?/ProxyExternal/' . \RainLoop\Utils::EncodeKeyValues(array('Rnd' => \md5(\microtime(true)), 'Token' => \RainLoop\Utils::GetConnectionToken(), 'Url' => $sUrl)) . '/';
                         };
                     }
                     $mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false, false, $fAdditionalExternalFilter);
                     $mResult['ExternalProxy'] = null !== $fAdditionalExternalFilter;
                     $mResult['Plain'] = $sPlain;
                     //					$mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
                     $mResult['TextHash'] = \md5($mResult['Html'] . $mResult['Plain']);
                     $mResult['TextPartIsTrimmed'] = $mResponse->TextPartIsTrimmed();
                     $mResult['PgpSigned'] = $mResponse->PgpSigned();
                     $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();
                     $mResult['PgpSignature'] = $mResponse->PgpSignature();
                     unset($sHtml, $sPlain);
                     $mResult['HasExternals'] = $bHasExternals;
                     $mResult['HasInternals'] = \is_array($mFoundedCIDs) && 0 < \count($mFoundedCIDs) || \is_array($mFoundedContentLocationUrls) && 0 < \count($mFoundedContentLocationUrls);
                     $mResult['FoundedCIDs'] = $mFoundedCIDs;
                     $mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array('FoundedCIDs' => $mFoundedCIDs, 'FoundedContentLocationUrls' => $mFoundedContentLocationUrls)));
                     $mResult['ReadReceipt'] = $mResponse->ReadReceipt();
                     if (0 < \strlen($mResult['ReadReceipt']) && !$mResult['IsReadReceipt']) {
                         if (0 < \strlen($mResult['ReadReceipt'])) {
                             try {
                                 $oReadReceipt = \MailSo\Mime\Email::Parse($mResult['ReadReceipt']);
                                 if (!$oReadReceipt) {
                                     $mResult['ReadReceipt'] = '';
                                 }
                             } catch (\Exception $oException) {
                                 unset($oException);
                             }
                         }
                         if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher($oAccount)->Get(\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $mResult['Folder'], $mResult['Uid']), '0')) {
                             $mResult['ReadReceipt'] = '';
                         }
                     }
                 }
             } else {
                 if ('MailSo\\Mime\\Email' === $sClassName) {
                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()), 'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail(true)), 'DkimStatus' => $mResponse->GetDkimStatus(), 'DkimValue' => $mResponse->GetDkimValue()));
                 } else {
                     if ('RainLoop\\Providers\\AddressBook\\Classes\\Contact' === $sClassName) {
                         $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContact' => $mResponse->IdContact, 'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display), 'ReadOnly' => $mResponse->ReadOnly, 'IdPropertyFromSearch' => $mResponse->IdPropertyFromSearch, 'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters)));
                     } else {
                         if ('RainLoop\\Providers\\AddressBook\\Classes\\Tag' === $sClassName) {
                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContactTag' => $mResponse->IdContactTag, 'Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->Name), 'ReadOnly' => $mResponse->ReadOnly));
                         } else {
                             if ('RainLoop\\Providers\\AddressBook\\Classes\\Property' === $sClassName) {
                                 // Simple hack
                                 if ($mResponse && $mResponse->IsWeb()) {
                                     $mResponse->Value = \preg_replace('/(skype|ftp|http[s]?)\\\\:\\/\\//i', '$1://', $mResponse->Value);
                                 }
                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdProperty' => $mResponse->IdProperty, 'Type' => $mResponse->Type, 'TypeStr' => $mResponse->TypeStr, 'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value)));
                             } else {
                                 if ('MailSo\\Mail\\Attachment' === $sClassName) {
                                     $oAccount = $this->getAccountFromToken(false);
                                     $mFoundedCIDs = isset($aParameters['FoundedCIDs']) && \is_array($aParameters['FoundedCIDs']) && 0 < \count($aParameters['FoundedCIDs']) ? $aParameters['FoundedCIDs'] : null;
                                     $mFoundedContentLocationUrls = isset($aParameters['FoundedContentLocationUrls']) && \is_array($aParameters['FoundedContentLocationUrls']) && 0 < \count($aParameters['FoundedContentLocationUrls']) ? $aParameters['FoundedContentLocationUrls'] : null;
                                     if ($mFoundedCIDs || $mFoundedContentLocationUrls) {
                                         $mFoundedCIDs = \array_merge($mFoundedCIDs ? $mFoundedCIDs : array(), $mFoundedContentLocationUrls ? $mFoundedContentLocationUrls : array());
                                         $mFoundedCIDs = 0 < \count($mFoundedCIDs) ? $mFoundedCIDs : null;
                                     }
                                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Framed' => false, 'MimeIndex' => (string) $mResponse->MimeIndex(), 'MimeType' => $mResponse->MimeType(), 'FileName' => \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::ClearXss($mResponse->FileName(true))), 'EstimatedSize' => $mResponse->EstimatedSize(), 'CID' => $mResponse->Cid(), 'ContentLocation' => $mResponse->ContentLocation(), 'IsInline' => $mResponse->IsInline(), 'IsThumbnail' => $bThumb, 'IsLinked' => $mFoundedCIDs && \in_array(\trim(\trim($mResponse->Cid()), '<>'), $mFoundedCIDs) || $mFoundedContentLocationUrls && \in_array(\trim($mResponse->ContentLocation()), $mFoundedContentLocationUrls)));
                                     $mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']);
                                     if ($mResult['IsThumbnail']) {
                                         $mResult['IsThumbnail'] = $this->isFileHasThumbnail($mResult['FileName']);
                                     }
                                     $mResult['Download'] = \RainLoop\Utils::EncodeKeyValues(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeIndex' => $mResult['MimeIndex'], 'MimeType' => $mResult['MimeType'], 'FileName' => $mResult['FileName'], 'Framed' => $mResult['Framed']));
                                 } else {
                                     if ('MailSo\\Mail\\Folder' === $sClassName) {
                                         $aExtended = null;
                                         $mStatus = $mResponse->Status();
                                         if (\is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'])) {
                                             $aExtended = array('MessageCount' => (int) $mStatus['MESSAGES'], 'MessageUnseenCount' => (int) $mStatus['UNSEEN'], 'UidNext' => (string) $mStatus['UIDNEXT'], 'Hash' => \MailSo\Mail\MailClient::GenerateHash($mResponse->FullNameRaw(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT']));
                                         }
                                         $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => $mResponse->Name(), 'FullName' => $mResponse->FullName(), 'FullNameRaw' => $mResponse->FullNameRaw(), 'FullNameHash' => $this->hashFolderFullName($mResponse->FullNameRaw(), $mResponse->FullName()), 'Delimiter' => (string) $mResponse->Delimiter(), 'HasVisibleSubFolders' => $mResponse->HasVisibleSubFolders(), 'IsSubscribed' => $mResponse->IsSubscribed(), 'IsExists' => $mResponse->IsExists(), 'IsSelectable' => $mResponse->IsSelectable(), 'Flags' => $mResponse->FlagsLowerCase(), 'Extended' => $aExtended, 'SubFolders' => $this->responseObject($mResponse->SubFolders(), $sParent, $aParameters)));
                                     } else {
                                         if ('MailSo\\Mail\\MessageCollection' === $sClassName) {
                                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('MessageCount' => $mResponse->MessageCount, 'MessageUnseenCount' => $mResponse->MessageUnseenCount, 'MessageResultCount' => $mResponse->MessageResultCount, 'Folder' => $mResponse->FolderName, 'FolderHash' => $mResponse->FolderHash, 'UidNext' => $mResponse->UidNext, 'NewMessages' => $this->responseObject($mResponse->NewMessages), 'LastCollapsedThreadUids' => $mResponse->LastCollapsedThreadUids, 'Offset' => $mResponse->Offset, 'Limit' => $mResponse->Limit, 'Search' => $mResponse->Search));
                                         } else {
                                             if ('MailSo\\Mail\\AttachmentCollection' === $sClassName) {
                                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('InlineCount' => $mResponse->InlineCount()));
                                             } else {
                                                 if ('MailSo\\Mail\\FolderCollection' === $sClassName) {
                                                     $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Namespace' => $mResponse->GetNamespace(), 'FoldersHash' => isset($mResponse->FoldersHash) ? $mResponse->FoldersHash : '', 'IsThreadsSupported' => $mResponse->IsThreadsSupported, 'Optimized' => $mResponse->Optimized, 'SystemFolders' => isset($mResponse->SystemFolders) && \is_array($mResponse->SystemFolders) ? $mResponse->SystemFolders : array()));
                                                 } else {
                                                     if ($mResponse instanceof \MailSo\Base\Collection) {
                                                         $aList =& $mResponse->GetAsArray();
                                                         if (100 < \count($aList) && $mResponse instanceof \MailSo\Mime\EmailCollection) {
                                                             $aList = \array_slice($aList, 0, 100);
                                                         }
                                                         $mResult = $this->responseObject($aList, $sParent, $aParameters);
                                                         $bHook = false;
                                                     } else {
                                                         if ('RainLoop\\Providers\\AddressBook\\Classes\\Group' === $sClassName) {
                                                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdGroup' => $mResponse->IdGroup, 'Name' => $mResponse->Name, 'Contacts' => $this->responseObject($mResponse->Contacts, $sParent, $aParameters)));
                                                         } else {
                                                             if ('RainLoop\\Providers\\AddressBook\\Classes\\GroupContact' === $sClassName) {
                                                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContact' => $mResponse->IdContact, 'IdGroup' => $mResponse->IdGroup, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Phone' => $mResponse->Phone));
                                                             } else {
                                                                 $mResult = '["' . \get_class($mResponse) . '"]';
                                                                 $bHook = false;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($bHook) {
             $this->Plugins()->RunHook('filter.response-object', array($sClassName, $mResult), false);
         }
     } else {
         if (\is_array($mResponse)) {
             foreach ($mResponse as $iKey => $oItem) {
                 $mResponse[$iKey] = $this->responseObject($oItem, $sParent, $aParameters);
             }
             $mResult = $mResponse;
         }
     }
     unset($mResponse);
     return $mResult;
 }